﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class SalesOrderBLL
    {
        private static readonly IBillingEntityDA billingEntityDA = DataAccess.CreateBillingEntityDA();
        private static readonly ICarrierDA carrierDA = DataAccess.CreateCarrierDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private static readonly IContractDA contractDA = DataAccess.CreateContractDA();
        private string currentWhName;
        private static readonly ICustomerDA customerDA = DataAccess.CreateCustomerDA();
        private List<string> dataBaseID;
        private static readonly IInventoryMgtDA inventoryMgtDA = DataAccess.CreateInventoryMgtDA();
        private static readonly IOrderDetailDA orderDetailDA = DataAccess.CreateOrderDetailDA();
        private static readonly IOrdersDA ordersDA = DataAccess.CreateOrdersDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private static readonly IPickDetailDA pickDetailDA = DataAccess.CreatePickDetailDA();
        private static readonly IPreallocatePickDetailDA preallocatePickDetailDA = DataAccess.CreatePreallocatePickDetailDA();
        private PubParasInfo pubParasInfo;
        private static readonly IReceiptDetailDA receiptDetailDA = DataAccess.CreateReceiptDetailDA();
        private static readonly IRotationRuleDA rotataionRuleDA = DataAccess.CreateRotationRuleDA();
        private static readonly IRotationRuleDetailDA rotataionRuleDetailDA = DataAccess.CreateRotationRuleDetailDA();
        private static readonly ISalesOrderDA salesOrderDA = DataAccess.CreateSalesOrderDA();
        private static readonly ISalesOrderDetailDA salesOrderDetailDA = DataAccess.CreateSalesOrderDetailDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly IUomDA uomDA = DataAccess.CreateUomDA();

        public SalesOrderBLL()
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
        }

        public SalesOrderBLL(string currentWH)
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.currentWhName = currentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public SalesOrderBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.currentWhName = tempPubParasInfo.CurrentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string ConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            string strSID = string.Empty;
            string temp = string.Empty;
            try
            {
                for (int i = 0; orderID.Count > i; i++)
                {
                    string whLoginID = this.dataBaseID[0];
                    SalesOrderInfo salesOrderInfo = salesOrderDA.GetSalesOrderByID(orderID[i], whLoginID, this.pubParasInfo);
                    if (salesOrderInfo != null)
                    {
                        salesOrderDA.UpdateSalesOrderSubmitted(orderID[i], this.pubParasInfo.UserID, whLoginID);
                        salesOrderInfo.UpdatedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.UpdatedDate = DateTime.Now;
                        salesOrderInfo.SubmittedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.SubmittedDate = DateTime.Now;
                        salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(orderID[i], whLoginID, this.pubParasInfo);
                        OrdersInfo ordersInfo = new OrdersInfo();
                        ordersInfo.BAddress = salesOrderInfo.BAddress;
                        ordersInfo.BCity = salesOrderInfo.BCity;
                        ordersInfo.BCompany = salesOrderInfo.BCompany;
                        ordersInfo.BContact1 = salesOrderInfo.BContact1;
                        ordersInfo.BContact2 = salesOrderInfo.BContact2;
                        ordersInfo.BCountry = salesOrderInfo.BCountry;
                        ordersInfo.BCountryCode = salesOrderInfo.BCountryCode;
                        ordersInfo.BEmail1 = salesOrderInfo.BEmail1;
                        ordersInfo.BEmail2 = salesOrderInfo.BEmail2;
                        ordersInfo.BFax1 = salesOrderInfo.BFax1;
                        ordersInfo.BFax2 = salesOrderInfo.BFax2;
                        ordersInfo.BillToID = salesOrderInfo.BillToID;
                        ordersInfo.BPhone1 = salesOrderInfo.BPhone1;
                        ordersInfo.BPhone2 = salesOrderInfo.BPhone2;
                        ordersInfo.BState = salesOrderInfo.BState;
                        ordersInfo.BVat = salesOrderInfo.BVat;
                        ordersInfo.BZip = salesOrderInfo.BZip;
                        ordersInfo.CAddress = salesOrderInfo.CAddress;
                        ordersInfo.CarrierAddress = salesOrderInfo.CarrierAddress;
                        ordersInfo.CarrierCity = salesOrderInfo.CarrierCity;
                        ordersInfo.CarrierCountry = salesOrderInfo.CarrierCountry;
                        ordersInfo.CarrierCountryCode = salesOrderInfo.CarrierCountryCode;
                        ordersInfo.CarrierID = salesOrderInfo.CarrierID;
                        ordersInfo.CarrierName = salesOrderInfo.CarrierName;
                        ordersInfo.CarrierPhone = salesOrderInfo.CarrierPhone;
                        ordersInfo.CarrierProv = salesOrderInfo.CarrierProv;
                        ordersInfo.CarrierZip = salesOrderInfo.CarrierZip;
                        ordersInfo.CCity = salesOrderInfo.CCity;
                        ordersInfo.CCompany = salesOrderInfo.CCompany;
                        ordersInfo.CContact1 = salesOrderInfo.CContact1;
                        ordersInfo.CContact2 = salesOrderInfo.CContact2;
                        ordersInfo.CCountry = salesOrderInfo.CCountry;
                        ordersInfo.CCountryCode = salesOrderInfo.CCountryCode;
                        ordersInfo.CEmail1 = salesOrderInfo.CEmail1;
                        ordersInfo.CEmail2 = salesOrderInfo.CEmail2;
                        ordersInfo.CFax1 = salesOrderInfo.CFax1;
                        ordersInfo.CFax2 = salesOrderInfo.CFax2;
                        ordersInfo.ConsigneeID = salesOrderInfo.ConsigneeID;
                        ordersInfo.ContainerQty = salesOrderInfo.ContainerQty;
                        ordersInfo.ContainerType = "DC20FT";
                        ordersInfo.CountryDestination = salesOrderInfo.CountryDestination;
                        ordersInfo.CountryOfOrigin = salesOrderInfo.CountryOfOrigin;
                        ordersInfo.CPhone1 = salesOrderInfo.CPhone1;
                        ordersInfo.CPhone2 = salesOrderInfo.CPhone2;
                        ordersInfo.CProv = salesOrderInfo.CProv;
                        ordersInfo.CreatedBy = this.pubParasInfo.UserID;
                        ordersInfo.CreatedDate = DateTime.Now;
                        ordersInfo.CVat = salesOrderInfo.CVat;
                        ordersInfo.CZip = salesOrderInfo.CZip;
                        ordersInfo.DeliveryPlace = salesOrderInfo.DeliveryPlace;
                        ordersInfo.DepartureDate = salesOrderInfo.DepartureDate;
                        ordersInfo.DischargePlace = salesOrderInfo.DischargePlace;
                        ordersInfo.Door = salesOrderInfo.Door;
                        ordersInfo.DriverName = salesOrderInfo.DriverName;
                        ordersInfo.ExternalLoadID = salesOrderInfo.ExternalLoadID;
                        ordersInfo.ExternOrderID = salesOrderInfo.ExternOrderID;
                        ordersInfo.IncoTerms = salesOrderInfo.IncoTerms;
                        ordersInfo.IsActive = salesOrderInfo.IsActive;
                        ordersInfo.LoadID = salesOrderInfo.LoadID;
                        ordersInfo.OpenQty = salesOrderInfo.OpenQty;
                        ordersInfo.OrderGroup = "";
                        ordersInfo.ShipTogether = "N";
                        ordersInfo.UpdateSource = "";
                        ordersInfo.CoreReleaseID = "";
                        ordersInfo.ActualShipDate = salesOrderInfo.ActualShipDate;
                        ordersInfo.DeliveryDate = salesOrderInfo.RequestedDeliveryDate;
                        ordersInfo.DeliveryDate2 = salesOrderInfo.DeliveryDate2;
                        ordersInfo.OrderDate = salesOrderInfo.SubmittedDate;
                        ordersInfo.RequestedShipDate = salesOrderInfo.RequestedDeliveryDate;
                        ordersInfo.ReferenceNum = salesOrderInfo.OrderID;
                        ordersInfo.ExternOrderID = salesOrderInfo.ExternOrderID;
                        ordersInfo.OwnerID = salesOrderInfo.OwnerID;
                        ordersInfo.PaymentTerm = "Cash";
                        ordersInfo.Priority = salesOrderInfo.Priority;
                        ordersInfo.ProNumber = salesOrderInfo.ProNumber;
                        ordersInfo.Remark = salesOrderInfo.Remark;
                        ordersInfo.Remark2 = salesOrderInfo.Remark2;
                        ordersInfo.Route = salesOrderInfo.Route;
                        ordersInfo.Stage = salesOrderInfo.Stage;
                        ordersInfo.Status = salesOrderInfo.Status;
                        ordersInfo.Stop = salesOrderInfo.Stop;
                        ordersInfo.TrailerNumber = salesOrderInfo.TrailerNumber;
                        ordersInfo.TrailerOwner = salesOrderInfo.TrailerOwner;
                        ordersInfo.TransportationMode = salesOrderInfo.TransportationMode;
                        ordersInfo.TransportationService = salesOrderInfo.TransportationService;
                        ordersInfo.Type = "Online";
                        ordersInfo.Udf1 = salesOrderInfo.Udf1;
                        ordersInfo.Udf10 = salesOrderInfo.Udf10;
                        ordersInfo.Udf2 = salesOrderInfo.Udf2;
                        ordersInfo.Udf3 = salesOrderInfo.Udf3;
                        ordersInfo.Udf4 = salesOrderInfo.Udf4;
                        ordersInfo.Udf5 = salesOrderInfo.Udf5;
                        ordersInfo.Udf6 = salesOrderInfo.Udf6;
                        ordersInfo.Udf7 = salesOrderInfo.Udf7;
                        ordersInfo.Udf8 = salesOrderInfo.Udf8;
                        ordersInfo.Udf9 = salesOrderInfo.Udf9;
                        ordersInfo.UpdatedBy = this.pubParasInfo.UserID;
                        ordersInfo.UpdatedDate = DateTime.Now;
                        ordersInfo.WhID = salesOrderInfo.WhID;
                        ordersInfo.IsCopy = "N";
                        if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                        {
                            decimal contractDeposit = 0M;
                            decimal invAvailableTotalPrice = 0M;
                            decimal unShippingAmount = 0M;
                            TradePartnerInfo tradePartnerInfo = ownerDA.GetTradePartnerByID(salesOrderInfo.OwnerID, whLoginID);
                            if ((tradePartnerInfo.Finance_Logistical_Ctrl == "Y") && (tradePartnerInfo.Finance_Logistical_Calc_By.ToUpper() == "SKUPRICE"))
                            {
                                ContractInfo contractInfo = contractDA.GetContractByOwnerID(salesOrderInfo.OwnerID, "Y", whLoginID);
                                if (contractInfo == null)
                                {
                                    contractDeposit = 0M;
                                }
                                else
                                {
                                    contractDeposit = contractInfo.Deposit;
                                }
                                invAvailableTotalPrice = salesOrderDetailDA.GetOwnerAllInvDeposit(salesOrderInfo.OwnerID, whLoginID);
                                unShippingAmount = salesOrderDetailDA.GetAllOrderDetailUnshippingAmount(salesOrderInfo.OwnerID, whLoginID);
                            }
                            List<OrderDetailInfo> orderDetailList = new List<OrderDetailInfo>();
                            foreach (SalesOrderDetailInfo info in salesOrderInfo.SalesOrderDetailInfos)
                            {
                                OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
                                SkuInfo skuInfo = skuDA.GetSkuByID(info.OwnerID, info.SkuID, whLoginID);
                                if (skuInfo != null)
                                {
                                    orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                                    orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                                    orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                                    orderDetailInfo.SkuDescr = skuInfo.Descr;
                                    orderDetailInfo.UnitPrice = Convert.ToDouble(skuInfo.SalePrice);
                                    orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (skuInfo.SalePrice * orderDetailInfo.OriginalQty));
                                }
                                if (tradePartnerInfo.Finance_Logistical_Ctrl == "Y")
                                {
                                    unShippingAmount += skuInfo.CostPrice * info.OriginalQty;
                                    if ((invAvailableTotalPrice - unShippingAmount) < contractDeposit)
                                    {
                                        List<string> gInitLocal13 = new List<string>();
                                        gInitLocal13.Add((invAvailableTotalPrice - unShippingAmount).ToString());
                                        gInitLocal13.Add(contractDeposit.ToString());
                                        PublicMethod.GetInstance().ShowAlertMessage("F3020_001", this.pubParasInfo.UserLanguage, gInitLocal13);
                                    }
                                }
                                orderDetailInfo.ActualShipDate = info.ActualShipDate;
                                orderDetailInfo.AdjustedQty = info.AdjustedQty;
                                orderDetailInfo.AltSkuID = info.AltSkuID;
                                orderDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                                orderDetailInfo.CreatedDate = DateTime.Now;
                                orderDetailInfo.ExtendedPrice = info.ExtendedPrice;
                                orderDetailInfo.ExternLineID = info.ExternLineID;
                                orderDetailInfo.ExternOrderID = info.ExternOrderID;
                                orderDetailInfo.IsSubstitute = info.IsSubstitute;
                                orderDetailInfo.LineID = info.LineID;
                                orderDetailInfo.OkToSubstitute = info.OkToSubstitute;
                                orderDetailInfo.OpenQty = info.OpenQty;
                                orderDetailInfo.OrderID = info.OrderID;
                                orderDetailInfo.OriginalQty = info.OriginalQty;
                                orderDetailInfo.OwnerID = info.OwnerID;
                                orderDetailInfo.PackID = info.PackID;
                                orderDetailInfo.ProductCube = info.ProductCube;
                                orderDetailInfo.ProductWeight = info.ProductWeight;
                                orderDetailInfo.Remark = info.Remark;
                                orderDetailInfo.ShippedQty = info.ShippedQty;
                                orderDetailInfo.SkuID = info.SkuID;
                                orderDetailInfo.Status = info.Status;
                                orderDetailInfo.Tax01 = info.Tax01;
                                orderDetailInfo.Tax02 = info.Tax02;
                                orderDetailInfo.LotAttr01 = info.Udf1;
                                orderDetailInfo.Udf1 = "";
                                orderDetailInfo.Udf10 = info.Udf10;
                                orderDetailInfo.Udf2 = info.Udf2;
                                orderDetailInfo.Udf3 = info.Udf3;
                                orderDetailInfo.Udf4 = info.Udf4;
                                orderDetailInfo.Udf5 = info.Udf5;
                                orderDetailInfo.Udf6 = info.Udf6;
                                orderDetailInfo.Udf7 = info.Udf7;
                                orderDetailInfo.Udf8 = info.Udf8;
                                orderDetailInfo.Udf9 = info.Udf9;
                                orderDetailInfo.UnitPrice = info.UnitPrice;
                                orderDetailInfo.UomID = info.UomID;
                                orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                orderDetailInfo.UpdatedDate = DateTime.Now;
                                orderDetailInfo.WhID = info.WhID;
                                orderDetailInfo.EffectiveDate = DateTime.Now;
                                orderDetailInfo.PickCode = "";
                                orderDetailInfo.CartonGroup = "";
                                orderDetailInfo.LpnID = "";
                                orderDetailInfo.UpdateSource = "";
                                orderDetailInfo.QcRequired = "";
                                orderDetailInfo.QcAutoAdjust = "";
                                orderDetailInfo.ShipGroup01 = "";
                                orderDetailInfo.ShipGroup02 = "";
                                orderDetailInfo.ShipGroup03 = "";
                                orderDetailInfo.Lot = "";
                                orderDetailInfo.LotAttr01 = "";
                                orderDetailInfo.LotAttr02 = "";
                                orderDetailInfo.LotAttr03 = "";
                                orderDetailInfo.LotAttr06 = "";
                                orderDetailInfo.LotAttr07 = "";
                                orderDetailInfo.LotAttr08 = "";
                                orderDetailInfo.LotAttr09 = "OK";
                                orderDetailInfo.LotAttr10 = "";
                                orderDetailInfo.WpReleased = "";
                                orderDetailList.Add(orderDetailInfo);
                            }
                            ordersInfo.OrderDetailInfos = orderDetailList;
                        }
                        strSID = new OrdersBLL(this.pubParasInfo).InsertOrders(ordersInfo);
                        if (!string.IsNullOrEmpty(strSID))
                        {
                            temp = temp + strSID + "提交成功";
                            salesOrderDA.UpdateSalesOrderStatus(salesOrderInfo.OrderID, OrderStatus.Scheduled, this.pubParasInfo.UserID, whLoginID);
                            if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                            {
                                for (int n = 0; n < salesOrderInfo.SalesOrderDetailInfos.Count; n++)
                                {
                                    salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(salesOrderInfo.SalesOrderDetailInfos[n].OrderID, salesOrderInfo.SalesOrderDetailInfos[n].LineID.ToString(), OrderStatus.Scheduled, 0M, this.pubParasInfo.UserID, whLoginID);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string DeleteSalesOrderInfo(List<string> orderID)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            List<string> IntransitIDs = new List<string>();
            string temp = "";
            try
            {
                List<SalesOrderInfo> salesOrderInfos = new List<SalesOrderInfo>();
                SalesOrderInfo salesOrderInfo = null;
                foreach (string id in orderID)
                {
                    salesOrderInfo = salesOrderDA.GetSalesOrderByID(dataBase, tran, id, this.dataBaseID[0], this.pubParasInfo);
                    salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(dataBase, tran, id, this.dataBaseID[0], this.pubParasInfo);
                    salesOrderInfos.Add(salesOrderInfo);
                }
                salesOrderDetailDA.DeleteSalesOrderDetail(dataBase, tran, orderID, this.dataBaseID[0]);
                if (salesOrderDA.DeleteSalesOrder(dataBase, tran, orderID, this.dataBaseID[0]) > 0)
                {
                    for (int i = 0; i < orderID.Count; i++)
                    {
                        auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, salesOrderInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[i]);
                        if ((salesOrderInfos[i].SalesOrderDetailInfos != null) && (salesOrderInfos[i].SalesOrderDetailInfos.Count > 0))
                        {
                            for (int j = 0; j < salesOrderInfos[i].SalesOrderDetailInfos.Count; j++)
                            {
                                auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, salesOrderInfos[i].SalesOrderDetailInfos[j], null, AuditAction.Delete, this.pubParasInfo.UserID, "AREA_DETAIL", this.dataBaseID[0]);
                            }
                        }
                        temp = temp + orderID[i] + ",";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (temp.Length > 0)
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return temp;
        }

        public SalesOrderInfo GetImportByDataSet(DataSet ds)
        {
            string ImportFalse = string.Empty;
            int lineID = 10;
            SalesOrderInfo salesOrderInfo = new SalesOrderInfo();
            List<SalesOrderDetailInfo> salesOrderDetailInfoList = new List<SalesOrderDetailInfo>();
            try
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime CS00002;
                    SalesOrderDetailInfo salesOrderDetailInfo = new SalesOrderDetailInfo();
                    if (i == 0)
                    {
                        salesOrderInfo.OrderID = "";
                        salesOrderInfo.OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim();
                        salesOrderInfo.ConsigneeID = ds.Tables[0].Rows[i][1].ToString().Trim();
                        salesOrderInfo.OrderDate = DateTime.Now;
                        salesOrderInfo.RequestedDeliveryDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.ActualShipDate = CS00002;
                        salesOrderInfo.DeliveryDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.DeliveryDate2 = CS00002;
                        salesOrderInfo.Priority = "3";
                        salesOrderInfo.Type = "Standard";
                        salesOrderInfo.OpenQty = 0M;
                        salesOrderInfo.Status = "New";
                        salesOrderInfo.ExternOrderID = "";
                        CustomerInfo customerInfo = customerDA.GetCustomerByID(salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo);
                        if (customerInfo != null)
                        {
                            salesOrderInfo.CCompany = customerInfo.Company;
                            salesOrderInfo.CAddress = customerInfo.Address;
                            salesOrderInfo.CCity = customerInfo.City;
                            salesOrderInfo.CProv = "";
                            salesOrderInfo.CZip = customerInfo.Zip;
                            salesOrderInfo.CCountryCode = customerInfo.CountryCode;
                            salesOrderInfo.CCountry = customerInfo.Country;
                            salesOrderInfo.CVat = customerInfo.Vat;
                            salesOrderInfo.CContact1 = customerInfo.Contact1;
                            salesOrderInfo.CContact2 = customerInfo.Contact2;
                            salesOrderInfo.CEmail1 = customerInfo.Email1;
                            salesOrderInfo.CEmail2 = customerInfo.Email2;
                            salesOrderInfo.CPhone1 = customerInfo.Phone1;
                            salesOrderInfo.CPhone2 = customerInfo.Phone2;
                            salesOrderInfo.CFax1 = customerInfo.Fax1;
                            salesOrderInfo.CFax2 = customerInfo.Fax2;
                        }
                        else
                        {
                            salesOrderInfo.CCompany = "";
                            salesOrderInfo.CAddress = "";
                            salesOrderInfo.CCity = "";
                            salesOrderInfo.CProv = "";
                            salesOrderInfo.CZip = "";
                            salesOrderInfo.CCountryCode = "";
                            salesOrderInfo.CCountry = "";
                            salesOrderInfo.CVat = "";
                            salesOrderInfo.CContact1 = "";
                            salesOrderInfo.CContact2 = "";
                            salesOrderInfo.CEmail1 = "";
                            salesOrderInfo.CEmail2 = "";
                            salesOrderInfo.CPhone1 = "";
                            salesOrderInfo.CPhone2 = "";
                            salesOrderInfo.CFax1 = "";
                            salesOrderInfo.CFax2 = "";
                        }
                        salesOrderInfo.BillToID = "";
                        salesOrderInfo.BCompany = "";
                        salesOrderInfo.BAddress = "";
                        salesOrderInfo.BCity = "";
                        salesOrderInfo.BState = "";
                        salesOrderInfo.BZip = "";
                        salesOrderInfo.BCountryCode = "";
                        salesOrderInfo.BCountry = "";
                        salesOrderInfo.BContact1 = "";
                        salesOrderInfo.BContact2 = "";
                        salesOrderInfo.BEmail1 = "";
                        salesOrderInfo.BEmail2 = "";
                        salesOrderInfo.BPhone1 = "";
                        salesOrderInfo.BPhone2 = "";
                        salesOrderInfo.BFax1 = "";
                        salesOrderInfo.BFax2 = "";
                        salesOrderInfo.BVat = "";
                        salesOrderInfo.CarrierID = "";
                        salesOrderInfo.CarrierName = "";
                        salesOrderInfo.CarrierAddress = "";
                        salesOrderInfo.CarrierCity = "";
                        salesOrderInfo.CarrierProv = "";
                        salesOrderInfo.CarrierZip = "";
                        salesOrderInfo.CarrierCountryCode = "";
                        salesOrderInfo.CarrierCountry = "";
                        salesOrderInfo.CarrierPhone = "";
                        salesOrderInfo.DepartureDate = DateTime.Now;
                        salesOrderInfo.TrailerNumber = "";
                        salesOrderInfo.TrailerOwner = "";
                        salesOrderInfo.DriverName = "";
                        salesOrderInfo.ProNumber = "";
                        salesOrderInfo.Door = "";
                        salesOrderInfo.Route = "";
                        salesOrderInfo.Stop = "";
                        salesOrderInfo.Stage = "";
                        salesOrderInfo.TransportationMode = "";
                        salesOrderInfo.TransportationService = "";
                        salesOrderInfo.IncoTerms = "";
                        salesOrderInfo.PaymentTerm = "";
                        salesOrderInfo.ContainerType = "";
                        salesOrderInfo.ContainerQty = 0M;
                        salesOrderInfo.LoadID = "";
                        salesOrderInfo.ExternalLoadID = "";
                        salesOrderInfo.CountryOfOrigin = "";
                        salesOrderInfo.CountryDestination = "";
                        salesOrderInfo.DischargePlace = "";
                        salesOrderInfo.DeliveryPlace = "";
                        salesOrderInfo.Udf1 = "";
                        salesOrderInfo.Udf2 = "";
                        salesOrderInfo.Udf3 = "";
                        salesOrderInfo.Udf4 = "";
                        salesOrderInfo.Udf5 = "";
                        salesOrderInfo.Udf6 = "";
                        salesOrderInfo.Udf7 = "";
                        salesOrderInfo.Udf8 = "";
                        salesOrderInfo.Udf9 = "";
                        salesOrderInfo.Udf10 = "";
                        salesOrderInfo.Remark = "";
                        salesOrderInfo.Remark2 = "";
                        salesOrderInfo.IsActive = "Y";
                        salesOrderInfo.CreatedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.CreatedDate = DateTime.Now;
                        salesOrderInfo.UpdatedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.UpdatedDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.SubmittedDate = CS00002;
                        salesOrderInfo.SubmittedBy = "";
                    }
                    salesOrderDetailInfo.LineID = lineID;
                    salesOrderDetailInfo.OrderID = "";
                    salesOrderDetailInfo.ExternOrderID = "";
                    salesOrderDetailInfo.ExternLineID = "";
                    salesOrderDetailInfo.OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim();
                    salesOrderDetailInfo.SkuID = ds.Tables[0].Rows[i][2].ToString().Trim();
                    salesOrderDetailInfo.OriginalQty = (ds.Tables[0].Rows[i][3].ToString().Trim() == "") ? 0M : decimal.Parse(ds.Tables[0].Rows[i][3].ToString().Trim());
                    salesOrderDetailInfo.OpenQty = 0M;
                    salesOrderDetailInfo.ShippedQty = 0M;
                    salesOrderDetailInfo.AdjustedQty = 0M;
                    salesOrderDetailInfo.Status = "New";
                    salesOrderDetailInfo.StatusD = "新建";
                    salesOrderDetailInfo.UnitPrice = 0.0;
                    salesOrderDetailInfo.Tax01 = 0.0;
                    salesOrderDetailInfo.Tax02 = 0.0;
                    salesOrderDetailInfo.ExtendedPrice = 0.0;
                    CS00002 = new DateTime();
                    salesOrderDetailInfo.ActualShipDate = CS00002;
                    salesOrderDetailInfo.IsSubstitute = 0;
                    salesOrderDetailInfo.OkToSubstitute = 0;
                    if (ds.Tables[0].Columns.Contains("LotAttr01"))
                    {
                        salesOrderDetailInfo.Udf1 = ds.Tables[0].Rows[i]["LotAttr01"].ToString().Trim();
                    }
                    else if (ds.Tables[0].Columns.Contains("UDF1"))
                    {
                        salesOrderDetailInfo.Udf1 = ds.Tables[0].Rows[i]["UDF1"].ToString().Trim();
                    }
                    else
                    {
                        salesOrderDetailInfo.Udf1 = "";
                    }
                    if (ds.Tables[0].Columns.Contains("UDF2"))
                    {
                        salesOrderDetailInfo.Udf2 = ds.Tables[0].Rows[i]["UDF2"].ToString().Trim();
                    }
                    else
                    {
                        salesOrderDetailInfo.Udf2 = "";
                    }
                    if (ds.Tables[0].Columns.Contains("UDF3"))
                    {
                        salesOrderDetailInfo.Udf3 = ds.Tables[0].Rows[i]["UDF3"].ToString().Trim();
                    }
                    else
                    {
                        salesOrderDetailInfo.Udf3 = "";
                    }
                    if (ds.Tables[0].Columns.Contains("REMARK"))
                    {
                        salesOrderDetailInfo.Remark = ds.Tables[0].Rows[i]["REMARK"].ToString().Trim();
                    }
                    else
                    {
                        salesOrderDetailInfo.Remark = "";
                    }
                    salesOrderDetailInfo.Udf4 = "";
                    salesOrderDetailInfo.Udf5 = "";
                    salesOrderDetailInfo.Udf6 = "";
                    salesOrderDetailInfo.Udf7 = "";
                    salesOrderDetailInfo.Udf8 = "";
                    salesOrderDetailInfo.Udf9 = "";
                    salesOrderDetailInfo.Udf10 = "";
                    salesOrderDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                    salesOrderDetailInfo.CreatedDate = DateTime.Now;
                    salesOrderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                    salesOrderDetailInfo.UpdatedDate = DateTime.Now;
                    SkuInfo skuInfo = skuDA.GetSkuByID(salesOrderDetailInfo.OwnerID, salesOrderDetailInfo.SkuID, this.dataBaseID[0]);
                    if (skuInfo != null)
                    {
                        if (skuInfo.IsActive != "Y")
                        {
                            throw new Exception("Sku(货品 " + salesOrderDetailInfo.SkuID + ")未启用,导入失败");
                        }
                        salesOrderDetailInfo.SkuDescr = skuInfo.Descr;
                        PackInfo packInfo = packDA.GetPackByID(skuInfo.PackID, this.dataBaseID[0]);
                        if ((skuInfo.AlternateSkuInfos != null) && (skuInfo.AlternateSkuInfos.Count > 0))
                        {
                            salesOrderDetailInfo.AltSkuID = skuInfo.AlternateSkuInfos[0].AltSkuID;
                        }
                        else
                        {
                            salesOrderDetailInfo.AltSkuID = "";
                        }
                        salesOrderDetailInfo.UomID = packInfo.PackUom1;
                        salesOrderDetailInfo.PackID = skuInfo.PackID;
                        salesOrderDetailInfo.ProductWeight = skuInfo.GrossWgt * double.Parse(salesOrderDetailInfo.OriginalQty.ToString());
                        salesOrderDetailInfo.ProductCube = skuInfo.Cube * double.Parse(salesOrderDetailInfo.OriginalQty.ToString());
                        if (!string.IsNullOrEmpty(packInfo.PackUom1))
                        {
                            UomInfo uomInfo = uomDA.GetUomByID(packInfo.PackUom1, this.dataBaseID[0], this.pubParasInfo);
                            salesOrderDetailInfo.UomDescr = uomInfo.UomDescr;
                        }
                    }
                    else
                    {
                        ImportFalse = ImportFalse + string.Format("第{0}行货品{1}不存在!<br />", i + 1, salesOrderDetailInfo.SkuID);
                    }
                    salesOrderDetailInfoList.Add(salesOrderDetailInfo);
                    salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailInfoList;
                    lineID += 10;
                }
                if (((string.IsNullOrEmpty(ImportFalse) && (salesOrderInfo != null)) && (salesOrderInfo.SalesOrderDetailInfos != null)) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(salesOrderInfo.OwnerID, this.dataBaseID[0]))
                    {
                        ImportFalse = ImportFalse + string.Format("货主{0}不存在!", salesOrderInfo.OwnerID);
                    }
                    else if (!commonMethod.CheckAuthorizationOwnerByUserID(this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                    {
                        if (!carrierDA.CheckCarrierIDUnique(salesOrderInfo.CarrierID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                        }
                        else if (!carrierDA.CheckAuthorizationCarrierUserID(salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                    {
                        if (!customerDA.CheckCustomerIDUnique(salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            ImportFalse = ImportFalse + string.Format("客户{0}不存在!", salesOrderInfo.ConsigneeID);
                        }
                        else if (!customerDA.CheckAuthorizationCustomerIDUserID(salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                    {
                        if (!billingEntityDA.CheckBillingEntityIDUnique(salesOrderInfo.BillToID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                        }
                        else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.OrderID))
                    {
                        if (salesOrderDA.CheckSalesOrderIDUnique(salesOrderInfo.OrderID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OrderID });
                        }
                    }
                    else
                    {
                        salesOrderInfo.OrderID = commonMethod.GenNextNumStr("SALES_ORDER", this.dataBaseID[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                ImportFalse = ImportFalse + ex.Message;
            }
            if (!string.IsNullOrEmpty(ImportFalse))
            {
                salesOrderInfo.Remark = "Error:<br />" + ImportFalse;
            }
            return salesOrderInfo;
        }

        private List<OrderDetailInfo> GetInvConvertOrderDetailInfoBySkuIDOwnerID(ref SkuInfo skuInfo, SalesOrderDetailInfo info, string ownerID, string whLoginID, ref decimal qty)
        {
            List<OrderDetailInfo> orderDetailList = new List<OrderDetailInfo>();
            if (skuInfo == null)
            {
                skuInfo = commonMethod.GetSkuInfoByUserOwner(info.SkuID, this.pubParasInfo.UserID, whLoginID, this.pubParasInfo);
            }
            ownerID = ownerID.ToUpper().Replace("MAGNAMATERIE,", "");
            Dictionary<string, RotationRuleInfo> rotationRuleObjects = new Dictionary<string, RotationRuleInfo>();
            if (skuInfo != null)
            {
                RotationRuleInfo rotationRuleInfo = null;
                if (!rotationRuleObjects.ContainsKey(skuInfo.RotationRuleID))
                {
                    rotationRuleInfo = rotataionRuleDA.GetRotationRuleByID(skuInfo.RotationRuleID, this.dataBaseID[0]);
                    if (rotationRuleInfo == null)
                    {
                        throw new Exception("货品" + skuInfo.SkuID + "没有指定周转规则 分配失败！");
                    }
                    rotationRuleInfo.RotationRuleDetailInfo = rotataionRuleDetailDA.GetRotationRuleDetailListByID(rotationRuleInfo.RotationRuleID, this.dataBaseID[0]);
                    rotationRuleObjects.Add(rotationRuleInfo.RotationRuleID, rotationRuleInfo);
                }
                else
                {
                    rotationRuleObjects.TryGetValue(skuInfo.RotationRuleID, out rotationRuleInfo);
                }
                string orderBy = string.Empty;
                if ((rotationRuleInfo != null) && ((rotationRuleInfo.RotationRuleDetailInfo != null) && (rotationRuleInfo.RotationRuleDetailInfo.Count > 0)))
                {
                    orderBy = " ORDER BY ";
                    for (int n = 0; n < rotationRuleInfo.RotationRuleDetailInfo.Count; n++)
                    {
                        if (rotationRuleInfo.RotationRuleDetailInfo[n].IsActive.ToUpper() == "Y")
                        {
                            string CS00002 = orderBy;
                            orderBy = CS00002 + rotationRuleInfo.RotationRuleDetailInfo[n].LotAttributes + " " + rotationRuleInfo.RotationRuleDetailInfo[n].Rotation + ",";
                        }
                    }
                    orderBy = orderBy.Substring(0, orderBy.Length - 1);
                }
                LotAttributeInfo lotAttribute = new LotAttributeInfo {
                    LotAttr01 = info.Udf1,
                    OwnerID = "'" + ownerID.Replace(",", "','") + "'",
                    SkuID = skuInfo.SkuID,
                    Status = "OK"
                };
                List<InventoryInfo> inventoryInfos = inventoryMgtDA.GetInventoryInfoByLotAttribute(lotAttribute, orderBy, whLoginID);
                if ((inventoryInfos == null) || (inventoryInfos.Count <= 0))
                {
                    return orderDetailList;
                }
                foreach (InventoryInfo Invinfo in inventoryInfos)
                {
                    decimal totalInvQty = 0M;
                    if (Invinfo.Qty > 0M)
                    {
                        decimal invQty = (((((Invinfo.Qty - Invinfo.AllocatedQty) - Invinfo.PickedQty) - Invinfo.ArchiveQty) - Invinfo.ExpectedQty) - Invinfo.PickinprocessQty) - Invinfo.PendingMoveIn;
                        if (invQty >= qty)
                        {
                            totalInvQty = qty;
                            qty = 0M;
                        }
                        else if (invQty > 0M)
                        {
                            qty -= invQty;
                            totalInvQty += invQty;
                        }
                        else
                        {
                            continue;
                        }
                        OrderDetailInfo orderDetailInfo = null;
                        bool isNewOrderDetail = true;
                        for (int i = 0; i < orderDetailList.Count; i++)
                        {
                            if (orderDetailList[i].OwnerID.ToUpper() == Invinfo.OwnerID.ToUpper())
                            {
                                OrderDetailInfo local1 = orderDetailList[i];
                                local1.OriginalQty += totalInvQty;
                                isNewOrderDetail = false;
                                break;
                            }
                        }
                        if (isNewOrderDetail)
                        {
                            orderDetailInfo = new OrderDetailInfo {
                                OwnerID = Invinfo.OwnerID,
                                SkuID = Invinfo.SkuID,
                                OriginalQty = totalInvQty,
                                ShippedQty = 0M,
                                LineID = info.LineID,
                                OrderID = "",
                                ActualShipDate = info.ActualShipDate,
                                AdjustedQty = info.AdjustedQty,
                                AltSkuID = info.AltSkuID,
                                CreatedBy = this.pubParasInfo.UserID,
                                CreatedDate = DateTime.Now,
                                ExtendedPrice = info.ExtendedPrice,
                                ExternLineID = info.ExternLineID,
                                ExternOrderID = info.ExternOrderID,
                                IsSubstitute = info.IsSubstitute,
                                OkToSubstitute = info.OkToSubstitute,
                                OpenQty = totalInvQty
                            };
                            if (!string.IsNullOrEmpty(info.PackID))
                            {
                                orderDetailInfo.PackID = info.PackID;
                            }
                            else
                            {
                                orderDetailInfo.PackID = skuInfo.PackID;
                            }
                            if (!string.IsNullOrEmpty(info.UomID))
                            {
                                orderDetailInfo.UomID = info.UomID;
                            }
                            else
                            {
                                PackInfo packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                                orderDetailInfo.UomID = packInfo.PackUom1;
                            }
                            orderDetailInfo.ProductCube = info.ProductCube;
                            orderDetailInfo.ProductWeight = info.ProductWeight;
                            orderDetailInfo.Remark = info.Remark;
                            orderDetailInfo.Status = info.Status;
                            orderDetailInfo.Tax01 = info.Tax01;
                            orderDetailInfo.Tax02 = info.Tax02;
                            orderDetailInfo.LotAttr01 = info.Udf1;
                            orderDetailInfo.Udf1 = "";
                            orderDetailInfo.Udf10 = info.Udf10;
                            orderDetailInfo.Udf2 = info.Udf2;
                            orderDetailInfo.Udf3 = info.Udf3;
                            orderDetailInfo.Udf4 = info.Udf4;
                            orderDetailInfo.Udf5 = info.Udf5;
                            orderDetailInfo.Udf6 = info.Udf6;
                            orderDetailInfo.Udf7 = info.Udf7;
                            orderDetailInfo.Udf8 = info.Udf8;
                            orderDetailInfo.Udf9 = info.Udf9;
                            orderDetailInfo.UnitPrice = info.UnitPrice;
                            orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                            orderDetailInfo.UpdatedDate = DateTime.Now;
                            orderDetailInfo.WhID = info.WhID;
                            orderDetailInfo.EffectiveDate = DateTime.Now;
                            orderDetailInfo.PickCode = "";
                            orderDetailInfo.CartonGroup = "";
                            orderDetailInfo.LpnID = "";
                            orderDetailInfo.UpdateSource = "";
                            orderDetailInfo.QcRequired = "";
                            orderDetailInfo.QcAutoAdjust = "";
                            orderDetailInfo.ShipGroup01 = "";
                            orderDetailInfo.ShipGroup02 = "";
                            orderDetailInfo.ShipGroup03 = "";
                            orderDetailInfo.Lot = "";
                            orderDetailInfo.LotAttr02 = "";
                            orderDetailInfo.LotAttr03 = "";
                            orderDetailInfo.LotAttr06 = "";
                            orderDetailInfo.LotAttr07 = "";
                            orderDetailInfo.LotAttr08 = "";
                            orderDetailInfo.LotAttr09 = "";
                            orderDetailInfo.LotAttr10 = "";
                            orderDetailInfo.WpReleased = "";
                            orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                            orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                            orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                            orderDetailInfo.SkuDescr = skuInfo.Descr;
                            orderDetailInfo.UnitPrice = Convert.ToDouble(skuInfo.SalePrice);
                            orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (skuInfo.SalePrice * orderDetailInfo.OriginalQty));
                            orderDetailList.Add(orderDetailInfo);
                        }
                    }
                    if (qty == 0M)
                    {
                        return orderDetailList;
                    }
                }
            }
            return orderDetailList;
        }

        public DataSet GetSalesOrderByQueryEntity(SalesOrderQueryEntity salesOrderQueryEntity)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.OrderID))
            {
                sqlWhere.Add(" SO.ORDER_ID " + salesOrderQueryEntity.OrderID);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.OwnerID))
            {
                sqlWhere.Add(" SO.OWNER_ID " + salesOrderQueryEntity.OwnerID);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.ConsigneeID))
            {
                sqlWhere.Add(" SO.CONSIGNEE_ID " + salesOrderQueryEntity.ConsigneeID);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.OrderDate))
            {
                sqlWhere.Add(" ORDER_DATE " + salesOrderQueryEntity.OrderDate);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.RequestedDeliveryDate))
            {
                sqlWhere.Add(" REQUESTED_DELIVERY_DATE " + salesOrderQueryEntity.RequestedDeliveryDate);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.Type))
            {
                sqlWhere.Add(" SO.TYPE " + salesOrderQueryEntity.Type);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.ExternOrderID))
            {
                sqlWhere.Add(" SO.EXTERN_ORDER_ID " + salesOrderQueryEntity.ExternOrderID);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.Status))
            {
                sqlWhere.Add(" SO.STATUS " + salesOrderQueryEntity.Status);
            }
            if (!string.IsNullOrEmpty(salesOrderQueryEntity.CreatedBy))
            {
                sqlWhere.Add(" SO.CREATED_BY " + salesOrderQueryEntity.CreatedBy);
            }
            return salesOrderDA.GetSalesOrderByQueryList(sqlWhere, salesOrderQueryEntity, this.dataBaseID[0], this.pubParasInfo);
        }

        public SalesOrderInfo GetSalesOrderInfoByID(string salesOrderID)
        {
            SalesOrderInfo salesOrderInfo = salesOrderDA.GetSalesOrderByID(salesOrderID, this.dataBaseID[0], this.pubParasInfo);
            if (salesOrderInfo != null)
            {
                salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(salesOrderID, this.dataBaseID[0], this.pubParasInfo);
            }
            return salesOrderInfo;
        }

        public string ImportByDataSet(DataSet ds)
        {
            string ImportFalse = string.Empty;
            string ordersID = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            int lineID = 10;
            SalesOrderInfo salesOrderInfo = new SalesOrderInfo();
            List<SalesOrderDetailInfo> salesOrderDetailInfoList = new List<SalesOrderDetailInfo>();
            try
            {
                int i;
                for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime CS00002;
                    SalesOrderDetailInfo salesOrderDetailInfo = new SalesOrderDetailInfo();
                    if (i == 0)
                    {
                        salesOrderInfo.OrderID = "";
                        salesOrderInfo.OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim();
                        salesOrderInfo.ConsigneeID = ds.Tables[0].Rows[i][1].ToString().Trim();
                        salesOrderInfo.OrderDate = DateTime.Now;
                        salesOrderInfo.RequestedDeliveryDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.ActualShipDate = CS00002;
                        salesOrderInfo.DeliveryDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.DeliveryDate2 = CS00002;
                        salesOrderInfo.Priority = "3";
                        salesOrderInfo.Type = "Standard";
                        salesOrderInfo.OpenQty = 0M;
                        salesOrderInfo.Status = "New";
                        salesOrderInfo.ExternOrderID = "";
                        CustomerInfo customerInfo = customerDA.GetCustomerByID(salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo);
                        if (customerInfo != null)
                        {
                            salesOrderInfo.CCompany = customerInfo.Company;
                            salesOrderInfo.CAddress = customerInfo.Address;
                            salesOrderInfo.CCity = customerInfo.City;
                            salesOrderInfo.CProv = "";
                            salesOrderInfo.CZip = customerInfo.Zip;
                            salesOrderInfo.CCountryCode = customerInfo.CountryCode;
                            salesOrderInfo.CCountry = customerInfo.Country;
                            salesOrderInfo.CVat = customerInfo.Vat;
                            salesOrderInfo.CContact1 = customerInfo.Contact1;
                            salesOrderInfo.CContact2 = customerInfo.Contact2;
                            salesOrderInfo.CEmail1 = customerInfo.Email1;
                            salesOrderInfo.CEmail2 = customerInfo.Email2;
                            salesOrderInfo.CPhone1 = customerInfo.Phone1;
                            salesOrderInfo.CPhone2 = customerInfo.Phone2;
                            salesOrderInfo.CFax1 = customerInfo.Fax1;
                            salesOrderInfo.CFax2 = customerInfo.Fax2;
                        }
                        else
                        {
                            salesOrderInfo.CCompany = "";
                            salesOrderInfo.CAddress = "";
                            salesOrderInfo.CCity = "";
                            salesOrderInfo.CProv = "";
                            salesOrderInfo.CZip = "";
                            salesOrderInfo.CCountryCode = "";
                            salesOrderInfo.CCountry = "";
                            salesOrderInfo.CVat = "";
                            salesOrderInfo.CContact1 = "";
                            salesOrderInfo.CContact2 = "";
                            salesOrderInfo.CEmail1 = "";
                            salesOrderInfo.CEmail2 = "";
                            salesOrderInfo.CPhone1 = "";
                            salesOrderInfo.CPhone2 = "";
                            salesOrderInfo.CFax1 = "";
                            salesOrderInfo.CFax2 = "";
                        }
                        salesOrderInfo.BillToID = "";
                        salesOrderInfo.BCompany = "";
                        salesOrderInfo.BAddress = "";
                        salesOrderInfo.BCity = "";
                        salesOrderInfo.BState = "";
                        salesOrderInfo.BZip = "";
                        salesOrderInfo.BCountryCode = "";
                        salesOrderInfo.BCountry = "";
                        salesOrderInfo.BContact1 = "";
                        salesOrderInfo.BContact2 = "";
                        salesOrderInfo.BEmail1 = "";
                        salesOrderInfo.BEmail2 = "";
                        salesOrderInfo.BPhone1 = "";
                        salesOrderInfo.BPhone2 = "";
                        salesOrderInfo.BFax1 = "";
                        salesOrderInfo.BFax2 = "";
                        salesOrderInfo.BVat = "";
                        salesOrderInfo.CarrierID = "";
                        salesOrderInfo.CarrierName = "";
                        salesOrderInfo.CarrierAddress = "";
                        salesOrderInfo.CarrierCity = "";
                        salesOrderInfo.CarrierProv = "";
                        salesOrderInfo.CarrierZip = "";
                        salesOrderInfo.CarrierCountryCode = "";
                        salesOrderInfo.CarrierCountry = "";
                        salesOrderInfo.CarrierPhone = "";
                        salesOrderInfo.DepartureDate = DateTime.Now;
                        salesOrderInfo.TrailerNumber = "";
                        salesOrderInfo.TrailerOwner = "";
                        salesOrderInfo.DriverName = "";
                        salesOrderInfo.ProNumber = "";
                        salesOrderInfo.Door = "";
                        salesOrderInfo.Route = "";
                        salesOrderInfo.Stop = "";
                        salesOrderInfo.Stage = "";
                        salesOrderInfo.TransportationMode = "";
                        salesOrderInfo.TransportationService = "";
                        salesOrderInfo.IncoTerms = "";
                        salesOrderInfo.PaymentTerm = "";
                        salesOrderInfo.ContainerType = "";
                        salesOrderInfo.ContainerQty = 0M;
                        salesOrderInfo.LoadID = "";
                        salesOrderInfo.ExternalLoadID = "";
                        salesOrderInfo.CountryOfOrigin = "";
                        salesOrderInfo.CountryDestination = "";
                        salesOrderInfo.DischargePlace = "";
                        salesOrderInfo.DeliveryPlace = "";
                        salesOrderInfo.Udf1 = "";
                        salesOrderInfo.Udf2 = "";
                        salesOrderInfo.Udf3 = "";
                        salesOrderInfo.Udf4 = "";
                        salesOrderInfo.Udf5 = "";
                        salesOrderInfo.Udf6 = "";
                        salesOrderInfo.Udf7 = "";
                        salesOrderInfo.Udf8 = "";
                        salesOrderInfo.Udf9 = "";
                        salesOrderInfo.Udf10 = "";
                        salesOrderInfo.Remark = "";
                        salesOrderInfo.Remark2 = "";
                        salesOrderInfo.IsActive = "Y";
                        salesOrderInfo.CreatedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.CreatedDate = DateTime.Now;
                        salesOrderInfo.UpdatedBy = this.pubParasInfo.UserID;
                        salesOrderInfo.UpdatedDate = DateTime.Now;
                        CS00002 = new DateTime();
                        salesOrderInfo.SubmittedDate = CS00002;
                        salesOrderInfo.SubmittedBy = "";
                    }
                    salesOrderDetailInfo.LineID = lineID;
                    salesOrderDetailInfo.OrderID = "";
                    salesOrderDetailInfo.ExternOrderID = "";
                    salesOrderDetailInfo.ExternLineID = "";
                    salesOrderDetailInfo.OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim();
                    salesOrderDetailInfo.SkuID = ds.Tables[0].Rows[i][2].ToString().Trim();
                    salesOrderDetailInfo.OriginalQty = (ds.Tables[0].Rows[i][3].ToString().Trim() == "") ? 0M : decimal.Parse(ds.Tables[0].Rows[i][3].ToString().Trim());
                    salesOrderDetailInfo.Remark = ds.Tables[0].Rows[i][4].ToString().Trim();
                    salesOrderDetailInfo.OpenQty = 0M;
                    salesOrderDetailInfo.ShippedQty = 0M;
                    salesOrderDetailInfo.AdjustedQty = 0M;
                    salesOrderDetailInfo.Status = "New";
                    salesOrderDetailInfo.UnitPrice = 0.0;
                    salesOrderDetailInfo.Tax01 = 0.0;
                    salesOrderDetailInfo.Tax02 = 0.0;
                    salesOrderDetailInfo.ExtendedPrice = 0.0;
                    CS00002 = new DateTime();
                    salesOrderDetailInfo.ActualShipDate = CS00002;
                    salesOrderDetailInfo.IsSubstitute = 0;
                    salesOrderDetailInfo.OkToSubstitute = 0;
                    salesOrderDetailInfo.Udf1 = "";
                    salesOrderDetailInfo.Udf2 = "";
                    salesOrderDetailInfo.Udf3 = "";
                    salesOrderDetailInfo.Udf4 = "";
                    salesOrderDetailInfo.Udf5 = "";
                    salesOrderDetailInfo.Udf6 = "";
                    salesOrderDetailInfo.Udf7 = "";
                    salesOrderDetailInfo.Udf8 = "";
                    salesOrderDetailInfo.Udf9 = "";
                    salesOrderDetailInfo.Udf10 = "";
                    salesOrderDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                    salesOrderDetailInfo.CreatedDate = DateTime.Now;
                    salesOrderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                    salesOrderDetailInfo.UpdatedDate = DateTime.Now;
                    SkuInfo skuInfo = skuDA.GetSkuByID(salesOrderDetailInfo.OwnerID, salesOrderDetailInfo.SkuID, this.dataBaseID[0]);
                    if (skuInfo != null)
                    {
                        if (skuInfo.IsActive != "Y")
                        {
                            throw new Exception(salesOrderDetailInfo.SkuID + "( 货主" + salesOrderDetailInfo.OwnerID + "  Sku(货品 " + salesOrderDetailInfo.SkuID + ")未启用,导入失败");
                        }
                        PackInfo packInfo = packDA.GetPackByID(skuInfo.PackID, this.dataBaseID[0]);
                        if ((skuInfo.AlternateSkuInfos != null) && (skuInfo.AlternateSkuInfos.Count > 0))
                        {
                            salesOrderDetailInfo.AltSkuID = skuInfo.AlternateSkuInfos[0].AltSkuID;
                        }
                        else
                        {
                            salesOrderDetailInfo.AltSkuID = "";
                        }
                        salesOrderDetailInfo.UomID = packInfo.PackUom1;
                        salesOrderDetailInfo.PackID = skuInfo.PackID;
                        salesOrderDetailInfo.ProductWeight = skuInfo.GrossWgt * double.Parse(salesOrderDetailInfo.OriginalQty.ToString());
                        salesOrderDetailInfo.ProductCube = skuInfo.Cube * double.Parse(salesOrderDetailInfo.OriginalQty.ToString());
                        if (!string.IsNullOrEmpty(packInfo.PackUom1))
                        {
                            UomInfo uomInfo = uomDA.GetUomByID(packInfo.PackUom1, this.dataBaseID[0], this.pubParasInfo);
                            salesOrderDetailInfo.UomDescr = uomInfo.UomDescr;
                        }
                    }
                    else
                    {
                        ImportFalse = ImportFalse + string.Format("第{0}行货品{1}不存在!<br />", i + 1, salesOrderDetailInfo.SkuID);
                    }
                    salesOrderDetailInfoList.Add(salesOrderDetailInfo);
                    salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailInfoList;
                    lineID += 10;
                }
                if (((string.IsNullOrEmpty(ImportFalse) && (salesOrderInfo != null)) && (salesOrderInfo.SalesOrderDetailInfos != null)) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, this.dataBaseID[0]))
                    {
                        ImportFalse = ImportFalse + string.Format("货主{0}不存在!", salesOrderInfo.OwnerID);
                    }
                    else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                    {
                        if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                        }
                        else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                    {
                        if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            ImportFalse = ImportFalse + string.Format("客户{0}不存在!", salesOrderInfo.ConsigneeID);
                        }
                        else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                    {
                        if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, salesOrderInfo.BillToID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                        }
                        else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                        }
                    }
                    if (!string.IsNullOrEmpty(salesOrderInfo.OrderID))
                    {
                        if (salesOrderDA.CheckSalesOrderIDUnique(dataBase, tran, salesOrderInfo.OrderID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OrderID });
                        }
                    }
                    else
                    {
                        salesOrderInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "SALES_ORDER", this.dataBaseID[0]);
                    }
                    salesOrderInfo.CreatedDate = DateTime.Now;
                    salesOrderInfo.UpdatedDate = DateTime.Now;
                    if (salesOrderDA.InsertSalesOrder(dataBase, tran, salesOrderInfo, this.dataBaseID[0]) > 0)
                    {
                        auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, null, salesOrderInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER", this.dataBaseID[0]);
                        ordersID = salesOrderInfo.OrderID;
                    }
                    if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                    {
                        for (i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                        {
                            salesOrderInfo.SalesOrderDetailInfos[i].OrderID = salesOrderInfo.OrderID;
                            if (salesOrderDetailDA.CheckSalesOrderDetailIDUnique(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString(), this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString() });
                            }
                            else
                            {
                                salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                                salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                                salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                                salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                                salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], this.dataBaseID[0]);
                                auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", this.dataBaseID[0]);
                            }
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                ImportFalse = "Error:<br />" + ImportFalse;
                ImportFalse = ImportFalse + ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return (string.IsNullOrEmpty(ImportFalse) ? ordersID : ("Error:<br />" + ImportFalse));
        }

        public string InsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                {
                    if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, salesOrderInfo.BillToID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                    else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.OrderID))
                {
                    if (salesOrderDA.CheckSalesOrderIDUnique(dataBase, tran, salesOrderInfo.OrderID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OrderID });
                    }
                }
                else
                {
                    salesOrderInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "SALES_ORDER", this.dataBaseID[0]);
                }
                salesOrderInfo.CreatedDate = DateTime.Now;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.InsertSalesOrder(dataBase, tran, salesOrderInfo, this.dataBaseID[0]) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, null, salesOrderInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER", this.dataBaseID[0]);
                    ordersID = salesOrderInfo.OrderID;
                }
                if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    for (int i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                    {
                        salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                        if (salesOrderDetailDA.CheckSalesOrderDetailIDUnique(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString(), this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString() });
                        }
                        else
                        {
                            SkuInfo skuinfo = skuDA.GetSkuByID(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OwnerID, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                            if ((skuinfo == null) || string.IsNullOrEmpty(skuinfo.SkuID))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].SkuID });
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(skuinfo.CostPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (skuinfo.CostPrice * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], this.dataBaseID[0]);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", this.dataBaseID[0]);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string SalesOrderCancel(string orderID)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string strOrderID = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(orderID))
                {
                    List<OrdersInfo> orderinfo = ordersDA.GetOrdersByReferenceNumAndType(dataBase, tran, orderID, "Online", this.dataBaseID[0], this.pubParasInfo);
                    if ((orderinfo != null) && (orderinfo.Count > 0))
                    {
                        List<string> orderid = new List<string>();
                        foreach (OrdersInfo info in orderinfo)
                        {
                            if (info.Status.ToUpper() != "NEW")
                            {
                                throw new Exception(orderID + " 出库单状态不为新建无法取消");
                            }
                            orderid.Add(info.OrderID);
                        }
                        orderDetailDA.DeleteOrderDetail(dataBase, tran, orderid, this.dataBaseID);
                        ordersDA.DeleteOrders(dataBase, tran, orderid, this.dataBaseID);
                    }
                    salesOrderDA.UpdateSalesOrderStatus(dataBase, tran, orderID, OrderStatus.Cancelled, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    salesOrderDetailDA.UpdateSalesOrderDetailStatus(orderID, OrderStatus.Cancelled, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    strOrderID = orderID;
                    tran.Commit();
                }
                return strOrderID;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strOrderID;
        }

        public string TJConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            string strSID = string.Empty;
            string temp = string.Empty;
            try
            {
                for (int i = 0; orderID.Count > i; i++)
                {
                    string whLoginID = this.dataBaseID[0];
                    salesOrderDA.UpdateSalesOrderSubmitted(orderID[i], this.pubParasInfo.UserID, whLoginID);
                    SalesOrderInfo salesOrderInfo = salesOrderDA.GetSalesOrderByID(orderID[i], whLoginID, this.pubParasInfo);
                    if (salesOrderInfo != null)
                    {
                        salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(orderID[i], whLoginID, this.pubParasInfo);
                        if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                        {
                            int n;
                            OrdersInfo ordersInfo = new OrdersInfo {
                                BAddress = salesOrderInfo.BAddress,
                                BCity = salesOrderInfo.BCity,
                                BCompany = salesOrderInfo.BCompany,
                                BContact1 = salesOrderInfo.BContact1,
                                BContact2 = salesOrderInfo.BContact2,
                                BCountry = salesOrderInfo.BCountry,
                                BCountryCode = salesOrderInfo.BCountryCode,
                                BEmail1 = salesOrderInfo.BEmail1,
                                BEmail2 = salesOrderInfo.BEmail2,
                                BFax1 = salesOrderInfo.BFax1,
                                BFax2 = salesOrderInfo.BFax2,
                                BillToID = salesOrderInfo.BillToID,
                                BPhone1 = salesOrderInfo.BPhone1,
                                BPhone2 = salesOrderInfo.BPhone2,
                                BState = salesOrderInfo.BState,
                                BVat = salesOrderInfo.BVat,
                                BZip = salesOrderInfo.BZip,
                                CAddress = salesOrderInfo.CAddress,
                                CarrierAddress = salesOrderInfo.CarrierAddress,
                                CarrierCity = salesOrderInfo.CarrierCity,
                                CarrierCountry = salesOrderInfo.CarrierCountry,
                                CarrierCountryCode = salesOrderInfo.CarrierCountryCode,
                                CarrierID = salesOrderInfo.CarrierID,
                                CarrierName = salesOrderInfo.CarrierName,
                                CarrierPhone = salesOrderInfo.CarrierPhone,
                                CarrierProv = salesOrderInfo.CarrierProv,
                                CarrierZip = salesOrderInfo.CarrierZip,
                                CCity = salesOrderInfo.CCity,
                                CCompany = salesOrderInfo.CCompany,
                                CContact1 = salesOrderInfo.CContact1,
                                CContact2 = salesOrderInfo.CContact2,
                                CCountry = salesOrderInfo.CCountry,
                                CCountryCode = salesOrderInfo.CCountryCode,
                                CEmail1 = salesOrderInfo.CEmail1,
                                CEmail2 = salesOrderInfo.CEmail2,
                                CFax1 = salesOrderInfo.CFax1,
                                CFax2 = salesOrderInfo.CFax2,
                                ConsigneeID = salesOrderInfo.ConsigneeID,
                                ContainerQty = salesOrderInfo.ContainerQty,
                                ContainerType = "DC20FT",
                                CountryDestination = salesOrderInfo.CountryDestination,
                                CountryOfOrigin = salesOrderInfo.CountryOfOrigin,
                                CPhone1 = salesOrderInfo.CPhone1,
                                CPhone2 = salesOrderInfo.CPhone2,
                                CProv = salesOrderInfo.CProv,
                                CreatedBy = this.pubParasInfo.UserID,
                                CreatedDate = DateTime.Now,
                                CVat = salesOrderInfo.CVat,
                                CZip = salesOrderInfo.CZip,
                                DeliveryPlace = salesOrderInfo.DeliveryPlace,
                                DepartureDate = salesOrderInfo.DepartureDate,
                                DischargePlace = salesOrderInfo.DischargePlace,
                                Door = salesOrderInfo.Door,
                                DriverName = salesOrderInfo.DriverName,
                                ExternalLoadID = salesOrderInfo.ExternalLoadID,
                                ExternOrderID = salesOrderInfo.ExternOrderID,
                                IncoTerms = salesOrderInfo.IncoTerms,
                                IsActive = salesOrderInfo.IsActive,
                                LoadID = salesOrderInfo.LoadID,
                                OpenQty = salesOrderInfo.OpenQty,
                                OrderGroup = "",
                                ShipTogether = "N",
                                UpdateSource = "",
                                ActualShipDate = salesOrderInfo.ActualShipDate,
                                DeliveryDate = salesOrderInfo.RequestedDeliveryDate,
                                DeliveryDate2 = salesOrderInfo.DeliveryDate2,
                                OrderDate = salesOrderInfo.SubmittedDate,
                                RequestedShipDate = salesOrderInfo.RequestedDeliveryDate,
                                ReferenceNum = salesOrderInfo.OrderID,
                                OwnerID = "",
                                PaymentTerm = "Cash",
                                Priority = salesOrderInfo.Priority,
                                ProNumber = salesOrderInfo.ProNumber,
                                Remark = salesOrderInfo.Remark,
                                Remark2 = salesOrderInfo.Remark2,
                                Route = salesOrderInfo.Route,
                                Stage = salesOrderInfo.Stage,
                                Status = salesOrderInfo.Status,
                                Stop = salesOrderInfo.Stop,
                                TrailerNumber = salesOrderInfo.TrailerNumber,
                                TrailerOwner = salesOrderInfo.TrailerOwner,
                                TransportationMode = salesOrderInfo.TransportationMode,
                                TransportationService = salesOrderInfo.TransportationService,
                                Type = "Online",
                                Udf1 = salesOrderInfo.Udf1,
                                Udf10 = salesOrderInfo.Udf10,
                                Udf2 = salesOrderInfo.Udf2,
                                Udf3 = salesOrderInfo.Udf3,
                                Udf4 = salesOrderInfo.Udf4,
                                Udf5 = salesOrderInfo.Udf5,
                                Udf6 = salesOrderInfo.Udf6,
                                Udf7 = salesOrderInfo.Udf7,
                                Udf8 = salesOrderInfo.Udf8,
                                Udf9 = salesOrderInfo.Udf9,
                                UpdatedBy = this.pubParasInfo.UserID,
                                UpdatedDate = DateTime.Now,
                                WhID = salesOrderInfo.WhID,
                                CoreReleaseID = ""
                            };
                            List<OrderDetailInfo> orderDetailList = new List<OrderDetailInfo>();
                            string stro = salesOrderInfo.SalesOrderDetailInfos[0].OwnerID;
                            string[] strOwner = stro.Split(new char[] { ',' });
                            foreach (SalesOrderDetailInfo info in salesOrderInfo.SalesOrderDetailInfos)
                            {
                                PackInfo packInfo;
                                string tmpOwnerID;
                                decimal orderQty = info.OriginalQty;
                                SkuInfo skuInfo = null;
                                RotationRuleInfo rotationRuleInfo = null;
                                List<InventoryInfo> inventoryInfos = null;
                                skuInfo = skuDA.GetSkuByID("MAGNAMATERIE", info.SkuID, whLoginID);
                                if (skuInfo != null)
                                {
                                    rotationRuleInfo = rotataionRuleDA.GetRotationRuleByID(skuInfo.RotationRuleID, this.dataBaseID[0]);
                                    string orderBy = string.Empty;
                                    if ((rotationRuleInfo != null) && ((rotationRuleInfo.RotationRuleDetailInfo != null) && (rotationRuleInfo.RotationRuleDetailInfo.Count > 0)))
                                    {
                                        orderBy = " ORDER BY ";
                                        n = 0;
                                        while (n < rotationRuleInfo.RotationRuleDetailInfo.Count)
                                        {
                                            if (rotationRuleInfo.RotationRuleDetailInfo[n].IsActive.ToUpper() == "Y")
                                            {
                                                string CS00004 = orderBy;
                                                orderBy = CS00004 + rotationRuleInfo.RotationRuleDetailInfo[n].LotAttributes + " " + rotationRuleInfo.RotationRuleDetailInfo[n].Rotation + ",";
                                            }
                                            n++;
                                        }
                                        orderBy = orderBy.Substring(0, orderBy.Length - 1);
                                    }
                                    LotAttributeInfo lotAttribute = new LotAttributeInfo {
                                        LotAttr01 = info.Udf1,
                                        OwnerID = "'Magnamaterie'",
                                        SkuID = info.SkuID,
                                        Status = "OK"
                                    };
                                    inventoryInfos = inventoryMgtDA.GetInventoryInfoByLotAttribute(lotAttribute, orderBy, this.dataBaseID[0]);
                                }
                                if ((inventoryInfos == null) || (inventoryInfos.Count <= 0))
                                {
                                    goto Label_0E18;
                                }
                                OrderDetailInfo orderDetailInfo = new OrderDetailInfo {
                                    ShippedQty = 0M,
                                    LineID = info.LineID,
                                    OrderID = "",
                                    ActualShipDate = info.ActualShipDate,
                                    AdjustedQty = info.AdjustedQty,
                                    AltSkuID = info.AltSkuID,
                                    CreatedBy = this.pubParasInfo.UserID,
                                    CreatedDate = DateTime.Now,
                                    ExtendedPrice = info.ExtendedPrice,
                                    ExternLineID = info.ExternLineID,
                                    ExternOrderID = info.ExternOrderID,
                                    IsSubstitute = info.IsSubstitute,
                                    OkToSubstitute = info.OkToSubstitute
                                };
                                if (!string.IsNullOrEmpty(info.PackID))
                                {
                                    orderDetailInfo.PackID = info.PackID;
                                }
                                else
                                {
                                    orderDetailInfo.PackID = skuInfo.PackID;
                                }
                                if (!string.IsNullOrEmpty(info.UomID))
                                {
                                    orderDetailInfo.UomID = info.UomID;
                                }
                                else
                                {
                                    packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                                    orderDetailInfo.UomID = packInfo.PackUom1;
                                }
                                orderDetailInfo.ProductCube = info.ProductCube;
                                orderDetailInfo.ProductWeight = info.ProductWeight;
                                orderDetailInfo.Remark = info.Remark;
                                orderDetailInfo.Status = info.Status;
                                orderDetailInfo.Tax01 = info.Tax01;
                                orderDetailInfo.Tax02 = info.Tax02;
                                orderDetailInfo.LotAttr01 = info.Udf1;
                                orderDetailInfo.Udf1 = "";
                                orderDetailInfo.Udf10 = info.Udf10;
                                orderDetailInfo.Udf2 = info.Udf2;
                                orderDetailInfo.Udf3 = info.Udf3;
                                orderDetailInfo.Udf4 = info.Udf4;
                                orderDetailInfo.Udf5 = info.Udf5;
                                orderDetailInfo.Udf6 = info.Udf6;
                                orderDetailInfo.Udf7 = info.Udf7;
                                orderDetailInfo.Udf8 = info.Udf8;
                                orderDetailInfo.Udf9 = info.Udf9;
                                orderDetailInfo.UnitPrice = info.UnitPrice;
                                orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                orderDetailInfo.UpdatedDate = DateTime.Now;
                                orderDetailInfo.WhID = info.WhID;
                                orderDetailInfo.EffectiveDate = DateTime.Now;
                                orderDetailInfo.PickCode = "";
                                orderDetailInfo.CartonGroup = "";
                                orderDetailInfo.LpnID = "";
                                orderDetailInfo.UpdateSource = "";
                                orderDetailInfo.QcRequired = "";
                                orderDetailInfo.QcAutoAdjust = "";
                                orderDetailInfo.ShipGroup01 = "";
                                orderDetailInfo.ShipGroup02 = "";
                                orderDetailInfo.ShipGroup03 = "";
                                orderDetailInfo.Lot = "";
                                orderDetailInfo.LotAttr02 = "";
                                orderDetailInfo.LotAttr03 = "";
                                orderDetailInfo.LotAttr06 = "";
                                orderDetailInfo.LotAttr07 = "";
                                orderDetailInfo.LotAttr08 = "";
                                orderDetailInfo.LotAttr09 = "";
                                orderDetailInfo.LotAttr10 = "";
                                orderDetailInfo.WpReleased = "";
                                orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                                orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                                orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                                orderDetailInfo.SkuDescr = skuInfo.Descr;
                                orderDetailInfo.UnitPrice = Convert.ToDouble(skuInfo.SalePrice);
                                orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (skuInfo.SalePrice * orderDetailInfo.OriginalQty));
                                decimal totalInvQty = 0M;
                            Label_0DBF:
                                foreach (InventoryInfo Invinfo in inventoryInfos)
                                {
                                    orderDetailInfo.OwnerID = Invinfo.OwnerID;
                                    orderDetailInfo.SkuID = Invinfo.SkuID;
                                    if (Invinfo.Qty > 0M)
                                    {
                                        decimal invQty = (((((Invinfo.Qty - Invinfo.AllocatedQty) - Invinfo.PickedQty) - Invinfo.ArchiveQty) - Invinfo.ExpectedQty) - Invinfo.PickinprocessQty) - Invinfo.PendingMoveIn;
                                        if (invQty > 0M)
                                        {
                                            if (invQty >= orderQty)
                                            {
                                                totalInvQty = orderQty;
                                                orderQty = 0M;
                                            }
                                            else if (invQty > 0M)
                                            {
                                                orderQty -= invQty;
                                                totalInvQty += invQty;
                                            }
                                            else
                                            {
                                                goto Label_0DBF;
                                            }
                                        }
                                    }
                                    if (orderQty == 0M)
                                    {
                                        goto Label_0DE0;
                                    }
                                }
                            Label_0DE0:
                                if (totalInvQty > 0M)
                                {
                                    orderDetailInfo.OriginalQty = totalInvQty;
                                    orderDetailInfo.OpenQty = totalInvQty;
                                    orderDetailList.Add(orderDetailInfo);
                                }
                            Label_0E18:
                                if (orderQty > 0M)
                                {
                                    List<OrderDetailInfo> orderOtherOwner = this.GetInvConvertOrderDetailInfoBySkuIDOwnerID(ref skuInfo, info, stro, whLoginID, ref orderQty);
                                    if ((orderOtherOwner != null) && (orderOtherOwner.Count > 0))
                                    {
                                        foreach (OrderDetailInfo odOwnerinfo in orderOtherOwner)
                                        {
                                            orderDetailList.Add(odOwnerinfo);
                                        }
                                    }
                                }
                                if (orderQty <= 0M)
                                {
                                    goto Label_183F;
                                }
                                string strOwnerID = receiptDetailDA.GetReceiptDetailInfoBySkuIDDescCreatedDate(info.OwnerID, info.SkuID, whLoginID, this.pubParasInfo);
                                if (string.IsNullOrEmpty(strOwnerID))
                                {
                                    goto Label_13BA;
                                }
                                bool isUpdate = false;
                                if (orderDetailList.Count > 0)
                                {
                                    foreach (OrderDetailInfo ODinfo in orderDetailList)
                                    {
                                        if ((ODinfo.OwnerID == strOwnerID) && (info.SkuID == ODinfo.SkuID))
                                        {
                                            ODinfo.OriginalQty += orderQty;
                                            isUpdate = true;
                                            goto Label_0F85;
                                        }
                                    }
                                }
                            Label_0F85:
                                if (!isUpdate)
                                {
                                    orderDetailInfo = new OrderDetailInfo {
                                        OwnerID = strOwnerID,
                                        SkuID = info.SkuID,
                                        OriginalQty = orderQty,
                                        ShippedQty = 0M,
                                        LineID = info.LineID,
                                        OrderID = "",
                                        ActualShipDate = info.ActualShipDate,
                                        AdjustedQty = info.AdjustedQty,
                                        AltSkuID = info.AltSkuID,
                                        CreatedBy = this.pubParasInfo.UserID,
                                        CreatedDate = DateTime.Now,
                                        ExtendedPrice = info.ExtendedPrice,
                                        ExternLineID = info.ExternLineID,
                                        ExternOrderID = info.ExternOrderID,
                                        IsSubstitute = info.IsSubstitute,
                                        OkToSubstitute = info.OkToSubstitute,
                                        OpenQty = orderQty
                                    };
                                    if (!string.IsNullOrEmpty(info.PackID))
                                    {
                                        orderDetailInfo.PackID = info.PackID;
                                    }
                                    else
                                    {
                                        orderDetailInfo.PackID = skuInfo.PackID;
                                    }
                                    if (!string.IsNullOrEmpty(info.UomID))
                                    {
                                        orderDetailInfo.UomID = info.UomID;
                                    }
                                    else
                                    {
                                        packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                                        orderDetailInfo.UomID = packInfo.PackUom1;
                                    }
                                    orderDetailInfo.ProductCube = info.ProductCube;
                                    orderDetailInfo.ProductWeight = info.ProductWeight;
                                    orderDetailInfo.Remark = info.Remark;
                                    orderDetailInfo.Status = info.Status;
                                    orderDetailInfo.Tax01 = info.Tax01;
                                    orderDetailInfo.Tax02 = info.Tax02;
                                    orderDetailInfo.LotAttr01 = info.Udf1;
                                    orderDetailInfo.Udf1 = "";
                                    orderDetailInfo.Udf10 = info.Udf10;
                                    orderDetailInfo.Udf2 = info.Udf2;
                                    orderDetailInfo.Udf3 = info.Udf3;
                                    orderDetailInfo.Udf4 = info.Udf4;
                                    orderDetailInfo.Udf5 = info.Udf5;
                                    orderDetailInfo.Udf6 = info.Udf6;
                                    orderDetailInfo.Udf7 = info.Udf7;
                                    orderDetailInfo.Udf8 = info.Udf8;
                                    orderDetailInfo.Udf9 = info.Udf9;
                                    orderDetailInfo.UnitPrice = info.UnitPrice;
                                    orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                    orderDetailInfo.UpdatedDate = DateTime.Now;
                                    orderDetailInfo.WhID = info.WhID;
                                    orderDetailInfo.EffectiveDate = DateTime.Now;
                                    orderDetailInfo.PickCode = "";
                                    orderDetailInfo.CartonGroup = "";
                                    orderDetailInfo.LpnID = "";
                                    orderDetailInfo.UpdateSource = "";
                                    orderDetailInfo.QcRequired = "";
                                    orderDetailInfo.QcAutoAdjust = "";
                                    orderDetailInfo.ShipGroup01 = "";
                                    orderDetailInfo.ShipGroup02 = "";
                                    orderDetailInfo.ShipGroup03 = "";
                                    orderDetailInfo.Lot = "";
                                    orderDetailInfo.LotAttr02 = "";
                                    orderDetailInfo.LotAttr03 = "";
                                    orderDetailInfo.LotAttr06 = "";
                                    orderDetailInfo.LotAttr07 = "";
                                    orderDetailInfo.LotAttr08 = "";
                                    orderDetailInfo.LotAttr09 = "";
                                    orderDetailInfo.LotAttr10 = "";
                                    orderDetailInfo.WpReleased = "";
                                    orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                                    orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                                    orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                                    orderDetailInfo.SkuDescr = skuInfo.Descr;
                                    orderDetailInfo.UnitPrice = Convert.ToDouble(skuInfo.SalePrice);
                                    orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (skuInfo.SalePrice * orderDetailInfo.OriginalQty));
                                    orderDetailList.Add(orderDetailInfo);
                                }
                                goto Label_183F;
                            Label_13BA:
                                tmpOwnerID = "Intiermaterie";
                                SkuInfo tmpskuInfo = skuDA.GetSkuByID("Intiermaterie", info.SkuID, whLoginID);
                                if (tmpskuInfo == null)
                                {
                                    tmpskuInfo = skuDA.GetSkuByID("Magnamaterie", info.SkuID, whLoginID);
                                    tmpOwnerID = "Magnamaterie";
                                }
                                if (tmpskuInfo != null)
                                {
                                    orderDetailInfo = new OrderDetailInfo {
                                        OwnerID = tmpOwnerID,
                                        SkuID = info.SkuID,
                                        OriginalQty = orderQty,
                                        ShippedQty = 0M,
                                        LineID = info.LineID,
                                        OrderID = "",
                                        ActualShipDate = info.ActualShipDate,
                                        AdjustedQty = info.AdjustedQty,
                                        AltSkuID = info.AltSkuID,
                                        CreatedBy = this.pubParasInfo.UserID,
                                        CreatedDate = DateTime.Now,
                                        ExtendedPrice = info.ExtendedPrice,
                                        ExternLineID = info.ExternLineID,
                                        ExternOrderID = info.ExternOrderID,
                                        IsSubstitute = info.IsSubstitute,
                                        OkToSubstitute = info.OkToSubstitute,
                                        OpenQty = orderQty
                                    };
                                    if (!string.IsNullOrEmpty(info.PackID))
                                    {
                                        orderDetailInfo.PackID = info.PackID;
                                    }
                                    else
                                    {
                                        orderDetailInfo.PackID = skuInfo.PackID;
                                    }
                                    if (!string.IsNullOrEmpty(info.UomID))
                                    {
                                        orderDetailInfo.UomID = info.UomID;
                                    }
                                    else
                                    {
                                        packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                                        orderDetailInfo.UomID = packInfo.PackUom1;
                                    }
                                    orderDetailInfo.ProductCube = info.ProductCube;
                                    orderDetailInfo.ProductWeight = info.ProductWeight;
                                    orderDetailInfo.Remark = info.Remark;
                                    orderDetailInfo.Status = info.Status;
                                    orderDetailInfo.Tax01 = info.Tax01;
                                    orderDetailInfo.Tax02 = info.Tax02;
                                    orderDetailInfo.LotAttr01 = info.Udf1;
                                    orderDetailInfo.Udf1 = "";
                                    orderDetailInfo.Udf10 = info.Udf10;
                                    orderDetailInfo.Udf2 = info.Udf2;
                                    orderDetailInfo.Udf3 = info.Udf3;
                                    orderDetailInfo.Udf4 = info.Udf4;
                                    orderDetailInfo.Udf5 = info.Udf5;
                                    orderDetailInfo.Udf6 = info.Udf6;
                                    orderDetailInfo.Udf7 = info.Udf7;
                                    orderDetailInfo.Udf8 = info.Udf8;
                                    orderDetailInfo.Udf9 = info.Udf9;
                                    orderDetailInfo.UnitPrice = info.UnitPrice;
                                    orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                    orderDetailInfo.UpdatedDate = DateTime.Now;
                                    orderDetailInfo.WhID = info.WhID;
                                    orderDetailInfo.EffectiveDate = DateTime.Now;
                                    orderDetailInfo.PickCode = "";
                                    orderDetailInfo.CartonGroup = "";
                                    orderDetailInfo.LpnID = "";
                                    orderDetailInfo.UpdateSource = "";
                                    orderDetailInfo.QcRequired = "";
                                    orderDetailInfo.QcAutoAdjust = "";
                                    orderDetailInfo.ShipGroup01 = "";
                                    orderDetailInfo.ShipGroup02 = "";
                                    orderDetailInfo.ShipGroup03 = "";
                                    orderDetailInfo.Lot = "";
                                    orderDetailInfo.LotAttr02 = "";
                                    orderDetailInfo.LotAttr03 = "";
                                    orderDetailInfo.LotAttr06 = "";
                                    orderDetailInfo.LotAttr07 = "";
                                    orderDetailInfo.LotAttr08 = "";
                                    orderDetailInfo.LotAttr09 = "";
                                    orderDetailInfo.LotAttr10 = "";
                                    orderDetailInfo.WpReleased = "";
                                    orderDetailInfo.PreallocateRuleID = tmpskuInfo.PreallocateRuleID;
                                    orderDetailInfo.AllocateRuleID = tmpskuInfo.AllocateRuleID;
                                    orderDetailInfo.SkuRotation = tmpskuInfo.RotationRuleID;
                                    orderDetailInfo.SkuDescr = tmpskuInfo.Descr;
                                    orderDetailInfo.UnitPrice = Convert.ToDouble(tmpskuInfo.SalePrice);
                                    orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (tmpskuInfo.SalePrice * orderDetailInfo.OriginalQty));
                                    orderDetailList.Add(orderDetailInfo);
                                }
                            Label_183F:;
                            }
                            if (orderDetailList.Count <= 0)
                            {
                                throw new Exception("请确认提交的货品的库存数量是否充足!");
                            }
                            OrdersBLL ordersBll = new OrdersBLL(this.pubParasInfo);
                            for (int w = 0; strOwner.Length > w; w++)
                            {
                                List<OrderDetailInfo> NewOrderList = new List<OrderDetailInfo>();
                                foreach (OrderDetailInfo info in orderDetailList)
                                {
                                    if (strOwner[w].ToUpper() == info.OwnerID.ToUpper())
                                    {
                                        NewOrderList.Add(info);
                                    }
                                }
                                if (NewOrderList.Count > 0)
                                {
                                    ordersInfo.OwnerID = strOwner[w];
                                    ordersInfo.IsCopy = "N";
                                    ordersInfo.OrderDetailInfos = NewOrderList;
                                    strSID = strSID + ordersBll.InsertOrders(ordersInfo) + ",";
                                    ordersInfo.OrderID = "";
                                }
                            }
                            if (!string.IsNullOrEmpty(strSID))
                            {
                                temp = temp + strSID + "提交成功";
                                salesOrderDA.UpdateSalesOrderStatus(salesOrderInfo.OrderID, OrderStatus.Scheduled, this.pubParasInfo.UserID, whLoginID);
                                if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                                {
                                    for (n = 0; n < salesOrderInfo.SalesOrderDetailInfos.Count; n++)
                                    {
                                        salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(salesOrderInfo.SalesOrderDetailInfos[n].OrderID, salesOrderInfo.SalesOrderDetailInfos[n].LineID.ToString(), OrderStatus.Scheduled, 0M, this.pubParasInfo.UserID, whLoginID);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string TJInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                {
                    if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, salesOrderInfo.BillToID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                    else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.OrderID))
                {
                    if (salesOrderDA.CheckSalesOrderIDUnique(dataBase, tran, salesOrderInfo.OrderID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OrderID });
                    }
                }
                else
                {
                    salesOrderInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "SALES_ORDER", this.dataBaseID[0]);
                }
                salesOrderInfo.CreatedDate = DateTime.Now;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.InsertSalesOrder(dataBase, tran, salesOrderInfo, this.dataBaseID[0]) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, null, salesOrderInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER", this.dataBaseID[0]);
                    ordersID = salesOrderInfo.OrderID;
                }
                if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    for (int i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                    {
                        salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                        if (salesOrderDetailDA.CheckSalesOrderDetailIDUnique(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString(), this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString() });
                        }
                        else
                        {
                            string[] strDetailOwner = salesOrderInfo.SalesOrderDetailInfos[i].OwnerID.Split(new char[] { ',' });
                            SkuInfo skuinfo = null;
                            decimal costPrice = 0M;
                            if (strDetailOwner.Length > 1)
                            {
                                skuinfo = commonMethod.GetSkuInfoByUserOwner(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.pubParasInfo.UserID, this.dataBaseID[0], this.pubParasInfo);
                            }
                            else
                            {
                                skuinfo = skuDA.GetSkuByID(dataBase, tran, salesOrderInfo.OwnerID, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                            }
                            if (skuinfo != null)
                            {
                                costPrice = skuinfo.CostPrice;
                            }
                            else
                            {
                                List<string> gInitLocal35 = new List<string> {
                                    salesOrderInfo.SalesOrderDetailInfos[i].SkuID
                                };
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, gInitLocal35);
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].PackID = skuinfo.PackID;
                            if (string.IsNullOrEmpty(salesOrderInfo.SalesOrderDetailInfos[i].UomID))
                            {
                                PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuinfo.PackID, this.dataBaseID[0]);
                                salesOrderInfo.SalesOrderDetailInfos[i].UomID = packInfo.PackUom1;
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(costPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (costPrice * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], this.dataBaseID[0]);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", this.dataBaseID[0]);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string TJUpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            string ordersID = string.Empty;
            string whLoginID = this.dataBaseID[0];
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
                string[] strOwner = salesOrderInfo.OwnerID.Split(new char[] { ',' });
                if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, whLoginID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, whLoginID, this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                salesOrderInfo.UpdatedBy = salesOrderInfo.CreatedBy;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.UpdateSalesOrder(dataBase, tran, salesOrderInfo, whLoginID) > 0)
                {
                    ordersID = salesOrderInfo.OrderID;
                    if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                    {
                        salesOrderDetailDA.DeleteSalesOrderDetail(dataBase, tran, new List<string> { ordersID }, whLoginID);
                        for (int i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                        {
                            string[] strDetailOwner = salesOrderInfo.SalesOrderDetailInfos[i].OwnerID.Split(new char[] { ',' });
                            string strcostPrice = string.Empty;
                            bool isSku = false;
                            SkuInfo skuinfo = null;
                            if (strDetailOwner.Length > 0)
                            {
                                for (int n = 0; strDetailOwner.Length > n; n++)
                                {
                                    skuinfo = skuDA.GetSkuByID(dataBase, tran, strDetailOwner[n], salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                                    if (!((skuinfo == null) || string.IsNullOrEmpty(skuinfo.SkuID)))
                                    {
                                        isSku = true;
                                        strcostPrice = skuinfo.CostPrice.ToString();
                                        break;
                                    }
                                }
                            }
                            if (!isSku)
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].SkuID });
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].PackID = skuinfo.PackID;
                            if (string.IsNullOrEmpty(salesOrderInfo.SalesOrderDetailInfos[i].UomID))
                            {
                                PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuinfo.PackID, this.dataBaseID[0]);
                                salesOrderInfo.SalesOrderDetailInfos[i].UomID = packInfo.PackUom1;
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(strcostPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (decimal.Parse(strcostPrice) * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                            salesOrderInfo.SalesOrderDetailInfos[i].LineID = (i + 1) * 10;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], whLoginID);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", whLoginID);
                        }
                    }
                    else
                    {
                        List<string> gInitLocal3e = new List<string> {
                            salesOrderInfo.OrderID
                        };
                        salesOrderDetailDA.DeleteSalesOrderDetail(dataBase, tran, gInitLocal3e, whLoginID);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string TTConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            string strSID = string.Empty;
            string temp = string.Empty;
            try
            {
                for (int i = 0; orderID.Count > i; i++)
                {
                    string whLoginID = this.dataBaseID[0];
                    salesOrderDA.UpdateSalesOrderSubmitted(orderID[i], this.pubParasInfo.UserID, whLoginID);
                    SalesOrderInfo salesOrderInfo = salesOrderDA.GetSalesOrderByID(orderID[i], whLoginID, this.pubParasInfo);
                    if (salesOrderInfo != null)
                    {
                        salesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(orderID[i], whLoginID, this.pubParasInfo);
                        OrdersInfo ordersInfo = new OrdersInfo {
                            BAddress = salesOrderInfo.BAddress,
                            BCity = salesOrderInfo.BCity,
                            BCompany = salesOrderInfo.BCompany,
                            BContact1 = salesOrderInfo.BContact1,
                            BContact2 = salesOrderInfo.BContact2,
                            BCountry = salesOrderInfo.BCountry,
                            BCountryCode = salesOrderInfo.BCountryCode,
                            BEmail1 = salesOrderInfo.BEmail1,
                            BEmail2 = salesOrderInfo.BEmail2,
                            BFax1 = salesOrderInfo.BFax1,
                            BFax2 = salesOrderInfo.BFax2,
                            BillToID = salesOrderInfo.BillToID,
                            BPhone1 = salesOrderInfo.BPhone1,
                            BPhone2 = salesOrderInfo.BPhone2,
                            BState = salesOrderInfo.BState,
                            BVat = salesOrderInfo.BVat,
                            BZip = salesOrderInfo.BZip,
                            CAddress = salesOrderInfo.CAddress,
                            CarrierAddress = salesOrderInfo.CarrierAddress,
                            CarrierCity = salesOrderInfo.CarrierCity,
                            CarrierCountry = salesOrderInfo.CarrierCountry,
                            CarrierCountryCode = salesOrderInfo.CarrierCountryCode,
                            CarrierID = salesOrderInfo.CarrierID,
                            CarrierName = salesOrderInfo.CarrierName,
                            CarrierPhone = salesOrderInfo.CarrierPhone,
                            CarrierProv = salesOrderInfo.CarrierProv,
                            CarrierZip = salesOrderInfo.CarrierZip,
                            CCity = salesOrderInfo.CCity,
                            CCompany = salesOrderInfo.CCompany,
                            CContact1 = salesOrderInfo.CContact1,
                            CContact2 = salesOrderInfo.CContact2,
                            CCountry = salesOrderInfo.CCountry,
                            CCountryCode = salesOrderInfo.CCountryCode,
                            CEmail1 = salesOrderInfo.CEmail1,
                            CEmail2 = salesOrderInfo.CEmail2,
                            CFax1 = salesOrderInfo.CFax1,
                            CFax2 = salesOrderInfo.CFax2,
                            ConsigneeID = salesOrderInfo.ConsigneeID,
                            ContainerQty = salesOrderInfo.ContainerQty,
                            ContainerType = "DC20FT",
                            CountryDestination = salesOrderInfo.CountryDestination,
                            CountryOfOrigin = salesOrderInfo.CountryOfOrigin,
                            CPhone1 = salesOrderInfo.CPhone1,
                            CPhone2 = salesOrderInfo.CPhone2,
                            CProv = salesOrderInfo.CProv,
                            CoreReleaseID = "",
                            IsDeclartion = "N",
                            CreatedBy = this.pubParasInfo.UserID,
                            CreatedDate = DateTime.Now,
                            CVat = salesOrderInfo.CVat,
                            CZip = salesOrderInfo.CZip,
                            DeliveryPlace = salesOrderInfo.DeliveryPlace,
                            DepartureDate = salesOrderInfo.DepartureDate,
                            DischargePlace = salesOrderInfo.DischargePlace,
                            Door = salesOrderInfo.Door,
                            DriverName = salesOrderInfo.DriverName,
                            ExternalLoadID = salesOrderInfo.ExternalLoadID,
                            ExternOrderID = salesOrderInfo.ExternOrderID,
                            IncoTerms = salesOrderInfo.IncoTerms,
                            IsActive = salesOrderInfo.IsActive,
                            LoadID = salesOrderInfo.LoadID,
                            OpenQty = salesOrderInfo.OpenQty,
                            OrderGroup = "",
                            ShipTogether = "N",
                            UpdateSource = "",
                            ActualShipDate = salesOrderInfo.ActualShipDate,
                            DeliveryDate = salesOrderInfo.RequestedDeliveryDate,
                            DeliveryDate2 = salesOrderInfo.DeliveryDate2,
                            OrderDate = salesOrderInfo.SubmittedDate,
                            RequestedShipDate = salesOrderInfo.RequestedDeliveryDate,
                            ReferenceNum = salesOrderInfo.OrderID,
                            OwnerID = salesOrderInfo.OwnerID,
                            PaymentTerm = "Cash",
                            Priority = salesOrderInfo.Priority,
                            ProNumber = salesOrderInfo.ProNumber,
                            Remark = salesOrderInfo.Remark,
                            Remark2 = salesOrderInfo.Remark2,
                            Route = salesOrderInfo.Route,
                            Stage = salesOrderInfo.Stage,
                            Status = salesOrderInfo.Status,
                            Stop = salesOrderInfo.Stop,
                            TrailerNumber = salesOrderInfo.TrailerNumber,
                            TrailerOwner = salesOrderInfo.TrailerOwner,
                            TransportationMode = salesOrderInfo.TransportationMode,
                            TransportationService = salesOrderInfo.TransportationService,
                            Type = "Online",
                            Udf1 = salesOrderInfo.Udf1,
                            Udf10 = salesOrderInfo.Udf10,
                            Udf2 = salesOrderInfo.Udf2,
                            Udf3 = salesOrderInfo.Udf3,
                            Udf4 = salesOrderInfo.Udf4,
                            Udf5 = salesOrderInfo.Udf5,
                            Udf6 = salesOrderInfo.Udf6,
                            Udf7 = salesOrderInfo.Udf7,
                            Udf8 = salesOrderInfo.Udf8,
                            Udf9 = salesOrderInfo.Udf9,
                            UpdatedBy = this.pubParasInfo.UserID,
                            UpdatedDate = DateTime.Now,
                            WhID = salesOrderInfo.WhID,
                            IsCopy = "N"
                        };
                        if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                        {
                            List<OrderDetailInfo> orderDetailList = new List<OrderDetailInfo>();
                            foreach (SalesOrderDetailInfo info in salesOrderInfo.SalesOrderDetailInfos)
                            {
                                OrderDetailInfo orderDetailInfo = new OrderDetailInfo {
                                    ActualShipDate = info.ActualShipDate,
                                    AdjustedQty = info.AdjustedQty,
                                    AltSkuID = info.AltSkuID,
                                    CreatedBy = this.pubParasInfo.UserID,
                                    CreatedDate = DateTime.Now,
                                    ExtendedPrice = info.ExtendedPrice,
                                    ExternLineID = info.ExternLineID,
                                    ExternOrderID = info.ExternOrderID,
                                    IsSubstitute = info.IsSubstitute,
                                    LineID = info.LineID,
                                    OkToSubstitute = info.OkToSubstitute,
                                    OpenQty = info.OpenQty,
                                    OrderID = info.OrderID,
                                    OriginalQty = info.OriginalQty,
                                    OwnerID = info.OwnerID,
                                    PackID = info.PackID,
                                    ProductCube = info.ProductCube,
                                    ProductWeight = info.ProductWeight,
                                    Remark = info.Remark,
                                    ShippedQty = info.ShippedQty,
                                    SkuID = info.SkuID,
                                    Status = info.Status,
                                    Tax01 = info.Tax01,
                                    Tax02 = info.Tax02,
                                    LotAttr09 = info.Udf1.ToUpper(),
                                    ExternalLot = info.Udf2
                                };
                                if (!string.IsNullOrEmpty(info.Udf3))
                                {
                                    orderDetailInfo.ProduceDate = DateTime.Parse(info.Udf3);
                                }
                                orderDetailInfo.Udf1 = "";
                                orderDetailInfo.Udf10 = info.Udf10;
                                orderDetailInfo.Udf2 = "";
                                orderDetailInfo.Udf3 = "";
                                orderDetailInfo.Udf4 = info.Udf4;
                                orderDetailInfo.Udf5 = info.Udf5;
                                orderDetailInfo.Udf6 = info.Udf6;
                                orderDetailInfo.Udf7 = info.Udf7;
                                orderDetailInfo.Udf8 = info.Udf8;
                                orderDetailInfo.Udf9 = info.Udf9;
                                orderDetailInfo.UnitPrice = info.UnitPrice;
                                orderDetailInfo.UomID = info.UomID;
                                orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                orderDetailInfo.UpdatedDate = DateTime.Now;
                                orderDetailInfo.WhID = info.WhID;
                                orderDetailInfo.EffectiveDate = DateTime.Now;
                                orderDetailInfo.PickCode = "";
                                orderDetailInfo.CartonGroup = "";
                                orderDetailInfo.LpnID = "";
                                orderDetailInfo.UpdateSource = "";
                                orderDetailInfo.QcRequired = "";
                                orderDetailInfo.QcAutoAdjust = "";
                                orderDetailInfo.ShipGroup01 = "";
                                orderDetailInfo.ShipGroup02 = "";
                                orderDetailInfo.ShipGroup03 = "";
                                orderDetailInfo.Lot = "";
                                orderDetailInfo.LotAttr01 = "";
                                orderDetailInfo.LotAttr02 = "";
                                orderDetailInfo.LotAttr03 = "";
                                orderDetailInfo.LotAttr06 = "";
                                orderDetailInfo.LotAttr07 = "";
                                orderDetailInfo.LotAttr08 = "";
                                orderDetailInfo.LotAttr10 = "";
                                orderDetailInfo.WpReleased = "";
                                SkuInfo skuInfo = skuDA.GetSkuByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                                if (skuInfo != null)
                                {
                                    orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                                    orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                                    orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                                    orderDetailInfo.SkuDescr = skuInfo.Descr;
                                    orderDetailInfo.UnitPrice = Convert.ToDouble(skuInfo.SalePrice);
                                    orderDetailInfo.ExtendedPrice = Convert.ToDouble((decimal) (skuInfo.SalePrice * orderDetailInfo.OriginalQty));
                                }
                                orderDetailList.Add(orderDetailInfo);
                            }
                            ordersInfo.OrderDetailInfos = orderDetailList;
                        }
                        strSID = new OrdersBLL(this.pubParasInfo).InsertOrders(ordersInfo);
                        if (!string.IsNullOrEmpty(strSID))
                        {
                            temp = temp + strSID + "提交成功";
                            salesOrderDA.UpdateSalesOrderStatus(salesOrderInfo.OrderID, OrderStatus.Scheduled, this.pubParasInfo.UserID, whLoginID);
                            if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                            {
                                for (int n = 0; n < salesOrderInfo.SalesOrderDetailInfos.Count; n++)
                                {
                                    salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(salesOrderInfo.SalesOrderDetailInfos[n].OrderID, salesOrderInfo.SalesOrderDetailInfos[n].LineID.ToString(), OrderStatus.Scheduled, 0M, this.pubParasInfo.UserID, whLoginID);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string TTInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                {
                    if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, salesOrderInfo.BillToID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                    else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.OrderID))
                {
                    if (salesOrderDA.CheckSalesOrderIDUnique(dataBase, tran, salesOrderInfo.OrderID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OrderID });
                    }
                }
                else
                {
                    salesOrderInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "SALES_ORDER", this.dataBaseID[0]);
                }
                salesOrderInfo.CreatedDate = DateTime.Now;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.InsertSalesOrder(dataBase, tran, salesOrderInfo, this.dataBaseID[0]) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, null, salesOrderInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER", this.dataBaseID[0]);
                    ordersID = salesOrderInfo.OrderID;
                }
                if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    for (int i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                    {
                        salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                        if (salesOrderDetailDA.CheckSalesOrderDetailIDUnique(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString(), this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].OrderID, salesOrderInfo.SalesOrderDetailInfos[i].LineID.ToString() });
                        }
                        else
                        {
                            SkuInfo skuinfo = skuDA.GetSkuByID(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OwnerID, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                            if ((skuinfo == null) || string.IsNullOrEmpty(skuinfo.SkuID))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].SkuID });
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(skuinfo.CostPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (skuinfo.CostPrice * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], this.dataBaseID[0]);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", this.dataBaseID[0]);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string TTUpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            string ordersID = string.Empty;
            string whLoginID = this.dataBaseID[0];
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, whLoginID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, whLoginID, this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                SalesOrderInfo oldSalesOrderInfo = salesOrderDA.GetSalesOrderByID(dataBase, tran, salesOrderInfo.OrderID, whLoginID, this.pubParasInfo);
                oldSalesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(dataBase, tran, salesOrderInfo.OrderID, whLoginID, this.pubParasInfo);
                salesOrderInfo.UpdatedBy = salesOrderInfo.CreatedBy;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.UpdateSalesOrder(dataBase, tran, salesOrderInfo, whLoginID) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, oldSalesOrderInfo, salesOrderInfo, AuditAction.Update, this.pubParasInfo.UserID, "SALES_ORDER", whLoginID);
                    ordersID = salesOrderInfo.OrderID;
                    if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                    {
                        int i;
                        if ((oldSalesOrderInfo.SalesOrderDetailInfos != null) && (oldSalesOrderInfo.SalesOrderDetailInfos.Count > 0))
                        {
                            for (i = 0; i < oldSalesOrderInfo.SalesOrderDetailInfos.Count; i++)
                            {
                                auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, oldSalesOrderInfo.SalesOrderDetailInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", whLoginID);
                            }
                        }
                        List<string> gInitLocal50 = new List<string> {
                            ordersID
                        };
                        salesOrderDetailDA.DeleteSalesOrderDetail(dataBase, tran, gInitLocal50, whLoginID);
                        for (i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                        {
                            SkuInfo skuinfo = skuDA.GetSkuByID(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OwnerID, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                            if ((skuinfo == null) || string.IsNullOrEmpty(skuinfo.SkuID))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].SkuID });
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(skuinfo.CostPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (skuinfo.CostPrice * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                            salesOrderInfo.SalesOrderDetailInfos[i].LineID = (i + 1) * 10;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], whLoginID);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", whLoginID);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string UpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            string ordersID = string.Empty;
            string whLoginID = this.dataBaseID[0];
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, whLoginID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, whLoginID, this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                SalesOrderInfo oldSalesOrderInfo = salesOrderDA.GetSalesOrderByID(dataBase, tran, salesOrderInfo.OrderID, whLoginID, this.pubParasInfo);
                oldSalesOrderInfo.SalesOrderDetailInfos = salesOrderDetailDA.GetSalesOrderDetailByID(dataBase, tran, salesOrderInfo.OrderID, whLoginID, this.pubParasInfo);
                salesOrderInfo.UpdatedBy = salesOrderInfo.CreatedBy;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.UpdateSalesOrder(dataBase, tran, salesOrderInfo, whLoginID) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, oldSalesOrderInfo, salesOrderInfo, AuditAction.Update, this.pubParasInfo.UserID, "SALES_ORDER", whLoginID);
                    ordersID = salesOrderInfo.OrderID;
                    if ((salesOrderInfo.SalesOrderDetailInfos != null) && (salesOrderInfo.SalesOrderDetailInfos.Count > 0))
                    {
                        int i;
                        if ((oldSalesOrderInfo.SalesOrderDetailInfos != null) && (oldSalesOrderInfo.SalesOrderDetailInfos.Count > 0))
                        {
                            for (i = 0; i < oldSalesOrderInfo.SalesOrderDetailInfos.Count; i++)
                            {
                                auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, oldSalesOrderInfo.SalesOrderDetailInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", whLoginID);
                            }
                        }
                        List<string> gInitLocal1a = new List<string> {
                            ordersID
                        };
                        salesOrderDetailDA.DeleteSalesOrderDetail(dataBase, tran, gInitLocal1a, whLoginID);
                        for (i = 0; i < salesOrderInfo.SalesOrderDetailInfos.Count; i++)
                        {
                            SkuInfo skuinfo = skuDA.GetSkuByID(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i].OwnerID, salesOrderInfo.SalesOrderDetailInfos[i].SkuID, this.dataBaseID[0]);
                            if ((skuinfo == null) || string.IsNullOrEmpty(skuinfo.SkuID))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.SalesOrderDetailInfos[i].SkuID });
                            }
                            salesOrderInfo.SalesOrderDetailInfos[i].UnitPrice = Convert.ToDouble(skuinfo.CostPrice);
                            salesOrderInfo.SalesOrderDetailInfos[i].ExtendedPrice = Convert.ToDouble((decimal) (skuinfo.CostPrice * salesOrderInfo.SalesOrderDetailInfos[i].OriginalQty));
                            salesOrderInfo.SalesOrderDetailInfos[i].OrderID = ordersID;
                            salesOrderInfo.SalesOrderDetailInfos[i].LineID = (i + 1) * 10;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].CreatedDate = DateTime.Now;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            salesOrderInfo.SalesOrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            salesOrderDetailDA.InsertSalesOrderDetail(dataBase, tran, salesOrderInfo.SalesOrderDetailInfos[i], whLoginID);
                            auditDataBLL.InsertAuditData<SalesOrderDetailInfo>(dataBase, tran, null, salesOrderInfo.SalesOrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SALES_ORDER_DETAIL", whLoginID);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string UpdateSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                if (!DataAccess.CreateOwnerDA().CheckTradePartnerIDUnique(dataBase, tran, salesOrderInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, salesOrderInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.OwnerID });
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, salesOrderInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.ConsigneeID))
                {
                    if (!customerDA.CheckCustomerIDUnique(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, salesOrderInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.ConsigneeID });
                    }
                }
                if (!string.IsNullOrEmpty(salesOrderInfo.BillToID))
                {
                    if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, salesOrderInfo.BillToID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_001", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                    else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, salesOrderInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { salesOrderInfo.BillToID });
                    }
                }
                SalesOrderInfo oldSalesOrderInfo = salesOrderDA.GetSalesOrderByID(dataBase, tran, salesOrderInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                salesOrderInfo.UpdatedBy = salesOrderInfo.CreatedBy;
                salesOrderInfo.UpdatedDate = DateTime.Now;
                if (salesOrderDA.UpdateSalesOrder(dataBase, tran, salesOrderInfo, this.dataBaseID[0]) > 0)
                {
                    auditDataBLL.InsertAuditData<SalesOrderInfo>(dataBase, tran, oldSalesOrderInfo, salesOrderInfo, AuditAction.Update, this.pubParasInfo.UserID, "SALES_ORDER", this.dataBaseID[0]);
                    ordersID = salesOrderInfo.OrderID;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }
    }
}

